Trying to vectorize this without reduce_sum
first following the examples from the user guide here 23.8 Vectorization | Stan User’s Guide and here 1.13 Multivariate priors for hierarchical models | Stan User’s Guide.
For ordered_logistic_lpmf(ints k | vector eta, vectors c)
, its clear how to create the vector for the first argument. But for the second I’m a bit at a loss because the vectors are of different length (items have different numbers of response categories). So while theta[jj[n]] * beta[ii[n]]
returns a real
for every n
, segment(alpha, pos_alpha[ii[n]], m[ii[n]])
returns a vector, the size of which can vary by n
.
{
vector[N] theta_beta_v;
?[N] alpha_v; // should be vectors of different size but ragged arrays are not supported
for (n in 1:N) {
theta_beta_v[n] = theta[jj[n]] * beta[ii[n]];
? = segment(alpha, pos_alpha[ii[n]], m[ii[n]]);
}
target += ordered_logistic_lpmf(r | theta_beta_v, alpha_v);
}
I think ordered_logistic_glm_lpmf
could be used once this has been figured out.