IRT model with random items

Well you can always have N_total - N_groups raw variables and store the position last elements of each group and then copy the raw variables directly to “actual” variables, skipping the last elements and then compute the last elements. This would require a bunch of for loops and it would be easy to do some of-by-one errors, but you should be able to get it going relatively easily.

Further, this simple trick is not always well-behaved, but there are some more complex solutions. One is to have a soft constraint, something like:

for(group in 1:N_groups) {
   sum(b[group]) ~ normal(0, 0.01 * N_group_members[group]); 
}

Or, even better, but more complex is described here: