How can I generate a random set of integers to be used dynamically within the transformed parameters
block for subsetting a vector in each MCMC iteration?
For example, I would like to randomly select 10 elements from a vector during each iteration.
I’m aware that I can generate this set in the transformed data
block using the following code:
int<lower=1, upper=m> set[m];
for (i in 1:m) {
set[i] = categorical_rng(rep_vector(1,m) / m);
}
However, this block is executed only once during initialization. Using the generated quantities block won’t allow me to use the set in other blocks.
Is there a way to generate a fresh set of random integers for subsetting in each MCMC iteration?