I'm working on multilevel models and want to know how they are estimated in R. For that purpose I'm reading amongst other things "Data Analysis Using Regression and Multilevel/Hierarchical Models" by A. Gelman and J. Hill to be found here. If you want to read in the book see p.395 - 400
They give the R code for Gibbs sampling. For better understanding, I want to code the Gibbs sampler by myself using their template. But there are two questions, I can't find the answers to regarding their code.
The hyperparameters are to be estimated using these formulas:
They describe each step of the iteration on p.399
When they implement the calculation of sigma.y
and sigma.a
they don't divide by n
or J
.
sigma.y.update <- function() {
sigma.y.new <- sqrt(sum((y-a[county])^2)/rchisq(1,n-1))
return (sigma.y.new)
}
sigma.a.update <- function() {
sigma.a.new <- sqrt(sum((a-mu.a)^2)/rchisq(1,J-1))
return (sigma.a.new)
}
What am I missing at this point? I hope you guys can help me on this.
y
. $\endgroup$sigma
andsigma hat
. $\endgroup$