rm(list=ls()); set.seed(20210323);
# filename <- "~/Bayes/Data/schools_data.txt"
# schools <- read.table(file=filemane, header=T, sep=",")
# rm(filename)
J <- 8 # J <- nrow(schools)
y <- c(28,8,-3,7,-1,1,18,12) # y <- schools$estimate
sigma <- c(15,10,16,11,9,11,10,18) # sigma <- schools$sd
library("rstan")
stan_model <- "
data{
int
real y[J];
real
}
parameters{
real mu;
real
vector[J] theta;
}
model{
theta ~ normal(mu, tau);
y ~ normal(theta, sigma);
}
”
schools_fit <- stan(model_code=stan_model, data=c("J", "y", "sigma"), iter=1000, chains=4) print(schools_fit) plot(schools_fit) summary(schools_fit)$summary schools_sim <- extract(schools_fit) names(schools_sim)