Hi there! I’d like some help figuring out how to specify my random effects structure. I have 10 sites, each with 3 traps on them, so I’d like the random effect of each trap nested within each site. I’m just a little confused how to nest them, and any help would be appreciated.
Below is what I’m currently working with. WHen I try to run it, it begins to run, but seems unable to ever actually do the sampling - it just gets stuck at 0% for all chains. Thanks!
data{
int o[156];
int RETrap[156];
int RESite[156];
int s[156];
vector[156] d;
}
parameters{
vector[30] b_0_rt; // trap level random effect
real <lower=0> sigma_trap;
vector[10] b_0_rs; // site level random effect
real<lower=0> sigma_site;
real <lower=0> b_1_e;
real b_1_m;
}
model{
vector[156] m;
vector[156] e;
vector[156] lambda;
b_1_m ~ normal( 0 , 2.5 );
sigma_site ~ exponential(1);
sigma_trap ~ exponential(1);
b_0_rs ~ normal(0, sigma_site); // prior for site level random effect
// Prior for site-level random effects
for (i in 1:156) {
b_0_rt[RETrap[i]] ~ normal(b_0_rs[RESite[i]], sigma_trap); // Trap's random effect is nested within site-level random effect
}
for ( i in 1:156 ) {
lambda[i] = exp(b_1_m*s[i] + b_0_rt[RETrap[i]]));
}
b_1_e ~ lognormal(0.01,1);
for ( i in 1:156 ) {
e[i] = b_1_e * d[i] ;
e[i] = inv_logit(e[i]);
}
for ( i in 1:156 ) {
m[i] = e[i] * lambda[i];
}
o ~ neg_binomial_2( m, phi );
}
[edit: escaped Stan code]