7 Hierarchical models: Uncovering the layers of data the Bayesian way
Bayesian hierarchical models are introduced as a way to represent data that naturally comes in groups, such as students within schools. Rather than forcing every observation into one shared distribution or treating each group as completely separate, a hierarchical approach acknowledges both common structure and group-specific differences. This makes it especially useful when some groups have limited data, because it can borrow strength across groups while still preserving meaningful variation.
The chapter develops this idea through the classic eight-schools coaching example, where each school has an estimated coaching effect and uncertainty. A fully separate model can overstate uncertainty and exaggerate extreme effects, while a fully pooled model can hide real differences between schools. The hierarchical model resolves this tension by assuming each school’s effect comes from a shared distribution with its own overall mean and spread, letting the data determine how similar or different the groups should be.
This shared structure produces shrinkage: individual group estimates are pulled toward the overall mean, with the amount of pulling controlled by the between-group spread. The result is more conservative and realistic inference, such as more believable estimates of whether coaching helps and which schools perform best. The chapter closes by noting that this logic applies broadly, from sports and web analytics to epidemiology and public health, wherever related groups must be modeled together without pretending they are identical.
The effect of coaching in terms of increase in students’ test scores by the separate model that assumes each school makes up a unique, independent distribution.
The posterior distribution of the effect of coaching under the pooled model. The effect centers around 7.7 points and ranges from −10 to 25.
A hierarchical model is a compromise between two extremes: a separate model that doesn’t share information across the subpopulations and a pooled model that assumes there’s no heterogeneity between groups.
The structure of the partial pooling model, showing multiple levels of dependence between the variables involved.
The half-normal distribution assigns probability to only half of the corresponding zero-centered normal distribution 𝒩(0, 𝜎²).
The posterior distribution of the variables in the hierarchical model. The base effect 𝜇 centers around 9, while the spread factor 𝜏 is more likely near 0. Individual effects 𝜃ᵢ are different but mostly resemble the base effect 𝜇.
Conditional average individual effect 𝐸[𝜃ᵢ | 𝜏] as a function of the spread factor 𝜏.
The effect of pooling in shrinking the individual effects towards a global trend.
Summary
- Hierarchical models explicitly model observations as arising from different groups that partially share common characteristics but also possess their own unique behavior. This is done by treating the statistics that describe the behavior of each group as samples drawn from a common distribution.
- Hierarchical models let us pool information across related groups while still allowing each group to have its own parameters.
- Hierarchical models solve the “all-or-nothing” choice between complete pooling (treating groups as identical) and no pooling (treating groups as totally separate).
- When the variation across groups is explicitly modeled, we can make inference about the difference in behavior between individual groups conditioned on small or large between-group variation.
- Posterior inference for hierarchical models automatically balances within-group data and across-group similarity, leading to shrinkage.
Grokking Bayes ebook for free