Hello !
I have been using the code below to fit a random intercepts (variance components) model.
data {
int<lower=1> n2 ;
int<lower=1> N ;
real y[N] ;
int school[N] ;
}
parameters {
real u2_z[n2] ;
real<lower=.1,upper=100> sigma ;
real<lower=.1,upper=100> sigma_u2;
real <lower=0,upper=1000> beta;
}
model {
real mu[N];
for (i in 1:N)
mu <- beta + u2_z[school] * sigma_u2;
y ~ normal(mu,sigma);
u2_z ~ normal(0, 1) ;
}
This would be fitted in lme4 as
lmer(outcome ~1 + (1|school.ID),data=dt.all)
I now want to include a term for random slope, which would be fitted in lme4 as
lmer(outcome ~1 + (year|school.ID),data=dt.all)
or
lmer(outcome ~1 + (year-1|school.ID),data=dt.all)
The variable year is a factor with 3 levels., Please can anyone help me modify the stan model?