I’m fairly new to Stan and Bayesian, so apologies if the resolution is fairly obvious.

I’m trying to estimate the following hierarchical model in Stan using the RStan interface, but i’m receiving this error when I try to engage the sampler:

[1] “Error in sampler$call_sampler(args_list[[i]]) : Initialization failed.”

error occurred during calling the sampler; sampling not done.

I’ve no clue how to even start resolving the issue. I’d really appreciate a solution or someone to point me in the right direction.

```
data {
int<lower=1> N; //Number of data points
int behaviour[N]; //Outcome - QRP Own Behaviour
//Clustering Factor
int respondent[N]; //Vector of respondent ID
int K; //Number of respondents
//Measurement Level Predictors
real prevalence[N]; //Pure measurement level variance for prevalence
//Person Level Predictors
real prevalence_b[N]; //Cluster means for prevalence
}
```

```
parameters {
real alpha_raw[K]; //Intercepts
real beta_p_r[K]; //Respondent slopes for prevalence
real beta_p_b; //Slope for person level prevalence
real<lower=0> sigma_resp[K]; //respondent SD
real alpha_top; //alpha - pooled
real<lower=0> alpha_sigma;
real beta_p_top; //slope coefficient for prevalence - pooled
real<lower=0> beta_p_sigma; //SD for prevalence - pooled
real lambda; //
}
```

```
transformed parameters {
real alpha[K];
for (i in 1:K) {
alpha[i] = alpha_sigma * alpha_raw[i] + alpha_top
+ beta_p_b * prevalence[i];
}
}
```

```
model{
for(i in 1:N) {
int a_respondent;
a_respondent = respondent[i];
behaviour[i] ~ lognormal(alpha[a_respondent] + beta_p_r[a_respondent]*prevalence[i], sigma_resp[a_respondent]);
}
//priors
alpha_raw ~ normal(0, 1);
beta_p_r ~ normal(beta_p_top, beta_p_sigma);
sigma_resp ~ student_t(0,10,1);
lambda~ normal(0,10);
//hyper-priors
alpha_top ~ normal(0,2);
beta_p_top ~ normal(0,2);
alpha_sigma ~ normal(0,2);
beta_p_sigma ~ normal(0,2);
beta_p_b ~ normal(0,2);
}
```

```
generated quantities{
real alpha_overall;
real beta_p_overall;
real logLikelihood[N];
vector[N] y_rep;
alpha_overall = lognormal_rng(alpha_top, alpha_sigma);
beta_p_overall = lognormal_rng(beta_p_top, beta_p_sigma);
for (i in 1:N) {
int a_respondent;
a_respondent = respondent[i];
y_rep[i] = lognormal_rng(alpha[a_respondent] + beta_p_r[a_respondent]*prevalence[i], sigma_resp[a_respondent]);
}
for (i in 1:N) {
int a_respondent;
a_respondent = respondent[i];
logLikelihood[i] = lognormal_lpdf(behaviour[i] | alpha[a_respondent] + beta_p_r[a_respondent]*prevalence[i], sigma_resp[a_respondent]);
}
}
```