Hey all,

Sorry to make yet another thread about this, but I’m still wrangling with some of the coding aspects of implementing our model. These are our parameter and modeling blocks:

```
parameters {
//Parameters
vector<lower=0,upper=1>[ns] guess;
matrix<lower=0>[ns,ncont] sens;
matrix[ns,ncont] crit;
matrix<lower=0>[ns,ncond] meta;
matrix<lower=0>[ns,ncond] nconf;
matrix<lower=0>[ns,ncond] pconf;
//Hyperparameters
vector[ncont] snm;
vector<lower=0>[ncont] sns;
vector[ncont] cm;
vector<lower=0>[ncont] cs;
vector[ncond] mm;
vector<lower=0>[ncond] ms;
vector[ncond] nccm;
vector<lower=0>[ncond] nccs;
vector[ncond] pccm;
vector<lower=0>[ncond] pccs;
}
```

```
model {
//Hyperpriors
snm ~ normal(0,1);
sns ~ lognormal(0,1);
cm ~ normal(0,1);
cs ~ lognormal(0,1);
mm ~ normal(0,1);
ms ~ lognormal(0,1);
nccm ~ normal(0,1);
nccs ~ lognormal(0,1);
pccm ~ normal(0,1);
pccs ~ lognormal(0,1);
guess ~ beta(1,193.0/3.0);
//Likelihood model (with local variable calculations)
for (cond in 1:ncond) {
matrix[sampn,ns] xtrans;
matrix[sampn,ns] sds;
//Priors
meta[:,cond] ~ lognormal(mm[cond],ms[cond]);
nconf[:,cond] ~ lognormal(nccm[cond],nccs[cond]);
pconf[:,cond] ~ lognormal(pccm[cond],pccs[cond]);
xtrans = logncdfinv(sampx,log(1/sqrt(meta[:,cond].^2+1)),sqrt(log(meta[:,cond].^2+1)));
sds = 1./xtrans;
for (cont in 1:ncont) {
sens[:,cont] ~ lognormal(snm[cont],sns[cont]);
crit[:,cont] ~ normal(cm[cont],cs[cont]);
if (sum(abs(oris[cond][cont])) == 0) {
} else {
matrix[nt,ns] sm;
vector[ns] sc;
matrix[nt,ns] se;
sm = oris[cond][cont].*rep_matrix(sens[:,cont]',nt);
sc = crit[:,cont].*sens[:,cont];
se = sm-rep_matrix(sc',nt);
target += reduce_sum(partial_sum_casandre_log, resps[cond][cont], 1, guess, sds, se, nconf[:,cond], pconf[:,cond]);
}
}
}
}
```

As you can see the sampling statements are inside of a for loop because the prior that the sample is drawn from has its own independent condition- or contrast-dependent noncentered paramterization. But is this actually something Stan is capable of doing? I ask because we are currently trying to debug why our model is highly autocorrelated and not converging (it has a pincushion shaped posterior). And I’m wondering if it has anything to do with how I’m trying to sample the parameters.

Thanks, as always, for any help!