I’m getting a strange error trying to extract a series of values from a matrix as a vector.
The model works fine when using a loop (where M
= 5524):
vector[M] yst_tmp;
...
for(m in 1:M) {
yst_tmp[m] = ystar[ii[m],jj[m]];
thr_tmp[m] = thresholds[gg[m],jj[m]];
}
y ~ ordered_logistic(yst_tmp, thr_tmp);
However when using to_vector
:
vector[M] yst_tmp;
...
yst_tmp = to_vector(ystar[ii,jj]);
for(m in 1:M) {
thr_tmp[m] = thresholds[gg[m],jj[m]];
}
y ~ ordered_logistic(yst_tmp, thr_tmp);
The model compiles, but errors when running with:
Exception: ordered_logistic: Integers has dimension = 5524, expecting dimension = 30514576;
This implies that the vector yst_tmp
is much larger than its declared size M
, which shouldn’t be possible.
Any ideas for how to debug this further? I’ve attached the two models and test data to this post.
F1_Base_Loop.stan (2.3 KB) F1_Base_to_vector.stan (2.4 KB)
test_data.R (84.1 KB)