Write down likelihood of observations given unobserved random effects \(f(y_{ij}\mid \beta_0, \beta, a_i, b_i)\) and “integrate out” unobserved effects
Involves high-dimensional integrals, that are often untractable, need for approximations…
Bayesian approach:
Treat \(a_i, b_i\) as model parameters with known prior, add prior on hyperparameter \(\Sigma\)
Specify priors on \(\beta_0, \beta, \sigma^2, \Sigma\)
Case study
stan_lmer
For the hierarchichal normal linear model we use the stan_lmer from the rstanarm R package.
If we want to use a general GLM with hierarchichal structure, we use the stan_glmerfunction.
The functions are Bayesian equivalents to the lmer, glmer functions of the lme4 R package, so check these out for further info on syntax etc. The section on model formulas in the documentation might be of interest
stan_lmer
Key inputs:
formula: y ~ fexp + (grp_exp | group)
can have multiple independent groups, e.g. y ~ fexp + (grp_exp_1 | group_1) + (grp_exp_2 | group_2)
nested groups, e.g. y ~ fexp + (grp_exp | group_1/group_2) equivalent to y ~ fexp + (grp_exp | group_1) + (grp_exp | group_1:group_2)
county floor logRadon
Length:919 Min. :0.0000 Min. :-2.3026
Class :character 1st Qu.:0.0000 1st Qu.: 0.6931
Mode :character Median :0.0000 Median : 1.3083
Mean :0.1665 Mean : 1.2648
3rd Qu.:0.0000 3rd Qu.: 1.8083
Max. :1.0000 Max. : 3.8774
Radon case study
Floor variable
Code
library("RColorBrewer")colours<-brewer.pal(n =12, name ="Paired")boxplot(logRadon ~ floor, data=RadonData,col=colours[c(2,6)],names=c('Basement','Floor'))
Radon case study
County variable
Code
RadonData$county_num =as.numeric(as.factor(RadonData$county))#table(RadonData$county)boxplot(logRadon ~ county_num, data = RadonData, xlab ='Counties')