/********************************************************************** * hierarchical normal model * * math[i, j] ~ normal(theta[i], sigma) * theta[i] ~ normal(mu, tau) * sigma^2 ~ scaled_inv_chi_square(1, 10) * mu ~ normal(50, 5) * tau^2 ~ scaled_inv_chi_square(1, 10) **********************************************************************/ data { int n; // number of observations int m; // number of groups real math[n]; // y int school[n]; // school ID, 1, ..., m } parameters { real theta[m]; // school mean real mu; real tau; real sigma; } model { sigma^2 ~ scaled_inv_chi_square(1, 10); tau^2 ~ scaled_inv_chi_square(1, 10); mu ~ normal(50, 5); theta ~ normal(mu, tau); for(i in 1:n) { math[i] ~ normal(theta[school[i]], sigma); } } /********************************************************************** * THE END **********************************************************************/