Hamiltonian Monte Carlo for Hierarchical Models 99
One-Way Normal (Centered)
data {
int<lower=0> J;
real y[J];
real<lower=0> sigma[J];
}
parameters {
real mu;
real<lower=0> tau;
real theta[J];
}
model {
mu ~ normal(0, 5);
tau ~ cauchy(0, 2.5);
theta ~ normal(mu, tau);
y ~ normal(theta, sigma);
}
One-Way Normal (Non-Centered)
data {
int<lower=0> J;
real y[J];
real<lower=0> sigma[J];
}
parameters {
real mu;
real<lower=0> tau;
real var_theta[J];
}
transformed parameters {
real theta[J];
for (j in 1:J) theta[j] <- tau * var_theta[j] + mu;
}
model {
mu ~ normal(0, 5);
tau ~ cauchy(0, 2.5);
var_theta ~ normal(0, 1);
y ~ normal(theta, sigma);
}