This is somewhat related to this post (How to manually code unit simplexes in Stan? - #9 by WardBrian) I did about manually creating unit simplexes for ragged array.
Basically, I need a ragged array of ordered vectors and the program needs to be general. The only way to achieve this using Stan’s ordered
command is by manually constructing N lots of ordered vectors, but this won’t be general. Therefore I need to code them manually as I have done below.
I have done this using the jacobian adjustment from the manual page here: 10.6 Ordered Vector | Stan Reference Manual), which as far as I understand is what happens under the hood when an ordered
vector is declared:
parameters {
matrix[T, max(Thr)] log_diffs;
vector[T] C_1;
}
transformed parameters {
matrix[T, max(Thr)] C_vec;
for (t in 1:T) {
C_vec[t,1] = C_1[t];
for (k in 2:Thr[t]) {
C_vec[t,k] = C_vec[t,k-1] + exp(log_diffs[t,k]);
}
}
}
model {
for (t in 1:T) {
to_vector(C_vec[c,t,1:Thr[t]]) ~ induced_dirichlet(rep_vector(1, Thr[t]+1), 0);
target += sum(log_diffs[c,t,1:Thr[t]]); // jacobian adjustment
}
}
However, this samples * very * badly compared to manually creating the ordered vectors using the ordered
command (otherwise the code is the same - also using the induced_dirichlet prior on the cutpoints). What have I done wrong?