Hi There, I keep running in to error when I am trying to fit the multilevel model using this RStan code. The error message ask for “p”, which I declared as the probability of transmission. this probability is in binomial distribution and “p” is present in the model. thus, I don’t know how to fix this.

```
data{
int<lower=0> M; // data length
int<lower=0> N; // number of animal per pen
int isol[M];
int s0[M];
int i0[M];
int dt[M];
int time[M];
real timeck[M,N];
int e0;
}
parameters{
vector[12] z;
//real a_bar;
real<lower=0> sigma;
real<lower=0> delta; // decay rate added
real<lower=0> beta; //transmission rate
}
transformed parameters{
real<lower=0> et;
for(i in 1:M){
et = e0*exp(-delta * time[i]);
for(j in 1:N){
et += ((1/delta)*(1-exp(-delta* timeck[i,j])));
}
}
}
model{
z ~ normal( 0 , 1 );
sigma ~ exponential( 0.5 );
delta ~ normal(0.01,0.1);
beta ~ normal(0.2,0.5);
for ( i in 1:M ) {
p[i] = beta+z[isol[i]]*sigma+log((((1-exp(-delta*dt[i]))*et) - (i0[i]*(1-(exp(-delta*dt[i]))-delta*dt[i]))/delta)/delta);
p[i] = 1-exp(-exp(p[i]));
}
ca ~ binomial( s0 , p );
}
generated quantities{
vector[M] log_lik;
vector[M] p;
vector[12]a;
a = beta+z * sigma;
for ( i in 1:M) {
p[i] = beta+z[isol[i]]*sigma+log((((1-exp(-delta*dt[i]))*et) - (i0[i]*(1-(exp(-delta*dt[i]))-delta*dt[i]))/delta)/delta);
p[i] = 1-exp(-exp(p[i]));
}
for (i in 1:M) log_lik[i]=binomial_lpmf( ca[i] | s0[i],p[i] );
}
```

The error message is the following

```
Variable "p" does not exist.
40: p[i] = beta+z[isol[i]]*sigma+log((((1-exp(-delta*dt[i]))*et) - (i0[i]*(1-(exp(- delta*dt[i]))-delta*dt[i]))/delta)/delta);
^
21: p[i] = 1-exp(-exp(p[i]));
```

Thank you for your help