Can someone please help with this? I have a data chain ‘mu’ that I want to randomly select the values at each iteration and utilize the selected values i the model block. So I created the transformed data block where a random integer is created as an index to be used to select the corresponding value of mu. But so far, it seems that the model block has been utilizing only one index for mu. How can I get the index to change at each iteration?

data {

int N;

int K;

int s1;

int s2;

real x[N];

real y[N];

real mu[9999];//Use when mu data is used

int id[N];

//real id_l[K];

}

transformed data {

real unif = uniform_rng(0,1);

real idn = ceil(unif * 9999);

int idx;

for (n in 1:9999) {

if (n == idn) {

idx = n;

break;

}

}

}

parameters {

real beta;

real<lower=0> sigma_1;

real<lower=0> sigma_2;

//real<lower=0> mu;//use when estimating mu

real<lower=1> muu;

real<lower=0> sigmau;

vector[K] U_raw;

}

transformed parameters {

real nu[N];

//real U[N];

//real k;

vector[K] U=U_raw*sigmau+muu;

// U = vector();

//U=U_rep[id_l U_ ];

```
for(n in 1:N){
nu[n]=U[id[n]]+beta*x[n]; #first model with log transformed data
//nu[n]=exp(U[id[n]])*(x[n])^beta;##second model with original data values
}
}
```

model {

```
U_raw ~std_normal();
for(n in 1:s1){
y[n] ~ logistic(nu[n],sigma_1);
}
for(n in s2:N){
//y[n] ~ logistic(nu[n]+mu,sigma_2);#Use this if we are estimating mu
print("idx",idx);
y[n] ~ logistic(nu[n]+mu[idx],sigma_2);
}
}
```