r - Nested Model in STAN? -


say want model random effect @ 2 levels, i.e. have 2 levels of nesting: individuals within parent group , parent groups within grandparent group. know how write basic model single random effect (below) examples these don't know how write equivalent to

lmer(resp ~ (1|a/b), data = dat) 

in lmer.

stan code single re. question is, how nest a within higher level b?

data{   int<lower=0> n;   int<lower=0> k;   matrix[n,k] x;   vector[n] price;   int j;   int<lower=1,upper=j> re[n]; } parameters{   vector[j] a;   real mu_a;   real tau;   real<lower=0> sigma_a;   real<lower=0> sigma;   vector[k] beta; } transformed parameters{   vector[n] mu_hat;   for(i in 1:n)     mu_hat[i] <- a[re[i]]; } model {   mu_a ~ normal(0,10);   tau ~ cauchy(0,5);   ~ normal(mu_a,sigma_a);   for(i in 1:n)     price[i] ~ normal(x[i]*beta + mu_hat[i], sigma); } " 

i'm not sure a/b notation in lmer, if want nested levels multiple layers deep, it's easy predictor. have irt model students (j in 1:j) nested in schools (school[j] in 1:s) , schools nested in cities (city[s] in 1:c).

[update 14 april 2017]

you can vectorize everything. rather this:

for (j in 1:j)    theta[j] ~ normal(alpha[school[j]], sigma_theta); (s in 1:s)   alpha[s] ~ normal(beta[city[s]], sigma_alpha); beta ~ normal(0, 5); 

you can have

theta ~ normal(alpha[school], sigma_theta); alpha ~ normal(beta[city], sigma_alpha); beta ~ normal(0, 5); 

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -