Specifying prior for row_vector of variable length

Hi!

In my programme’s parameters block I have this alpha_0 defined as:

row_vector[2] alpha_0[num_prod];

Later on, in the model block, I assign a prior to those parameters, vectorized over num_prod:

for (k in 1:2) {
  alpha_0[k] ~ normal(0, 1);
}

This has been working fine until I faced an unusual case of num_prod = 1. In this case, I believe alpha_0 should be a row vector of length two, so the above approach should still work, but it does not. How can I solve this issue? Thanks in advance!

alpha_0 is an array of length num_prod whose elements are row vectors of length 2. Accordingly, alpha_0[k] is a row vector not an array. The reason your for loop is failing is that if num_prod is 1, then alpha_0[1] exists, but alpha_0[2] does not. Your for loop should have been

for (k in 1:num_prod) {
  alpha_0[k] ~ normal(0, 1);
}

This also implies that whatever results you got with num_prod > 1 may very well be incorrect, unfortunately.