- Introduced by
- Gelfand & Smith (sampling-based approach); multilevel extension developed through 1990s Bayesian hierarchical modeling literature
- Year
- 1990s
- Type
- Bayesian computational inference
- Family
- Bayesian / computational
What does it do?
Multilevel MCMC applies Markov chain Monte Carlo sampling to hierarchical (multilevel) Bayesian models.
It draws samples from the joint posterior of both group-level and population-level parameters simultaneously, propagating uncertainty across levels and enabling inference in clustered or nested data structures where observations within groups share common distributional characteristics. It is not the same as multilevel Monte Carlo, a distinct variance-reduction method based on level-telescoping estimators, typically applied to stochastic differential equations.
The intuition behind the method
Imagine students nested within schools: each school has its own performance profile, but schools are drawn from a common population of schools. Multilevel MCMC fits these two layers together — it estimates school-specific parameters and the population distribution simultaneously. Neither level is analysed in isolation; information flows upward (pooling strength across groups) and downward (the population prior regularises each group's estimate). The result is a full posterior distribution over all parameters at every level, not just point estimates.
History
Gelfand and Smith (1990) reviewed sampling-based approaches to calculating marginal densities: stochastic substitution (the Gibbs sampler) and sampling-importance-resampling. They compared these approaches across joint probability structures and discussed their use for calculating Bayesian posterior densities in structured models. The multilevel (hierarchical) extension of Bayesian computation developed through the 1990s hierarchical modelling literature, which Gelman et al. (2013) treats at length.
When to use it
Use Multilevel MCMC when data are naturally clustered or nested (students in schools, patients in hospitals, measurements within subjects) and you need full Bayesian uncertainty for both group-level and population-level parameters. It is especially useful when group sizes vary widely, because information from larger groups stabilises estimates for smaller ones. It also suits analyses where prior information about variance components exists or where the research question is how variability is partitioned across levels. Do not use it when observations are independent with no grouping structure (ordinary Bayesian regression suffices), when run-time is severely constrained and a frequentist mixed-effects model gives an adequate approximation, or when there are very few groups, since hyperparameter estimation is then unreliable.
Limitations and considerations
- Computationally expensive: large hierarchies with many groups and parameters require substantial sampling time, especially when gradients are unavailable.
- Posterior geometry in multilevel models often exhibits funnel-shaped dependencies that slow mixing; non-centred parameterisation can help in some cases but requires expertise.
- Hyperpriors on variance components (e.g. the between-group SD) are influential and must be chosen carefully, as weakly informative choices can still bias results.
- With very few groups the population distribution is poorly identified and the posterior of hyperparameters is dominated by the prior.
- Convergence assessment is more demanding than in flat models because both group-level and hyperparameter chains must be checked.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Propagates uncertainty across all levels of the hierarchy within a single posterior, so credible intervals for group-specific and population-level parameters both reflect the variability at each level; how well those intervals are calibrated still depends on the chosen model and priors.
- Partial pooling stabilises estimates for small or data-sparse groups without discarding information from larger groups.
- Naturally accommodates imbalanced designs, missing data, and non-standard outcome distributions (e.g. Poisson, Bernoulli) within the same framework.
- The full posterior enables model comparison via LOO-CV or WAIC and posterior predictive checks.
- Can be specified in probabilistic programming languages (Stan, PyMC, JAGS) that handle the hierarchical structure without hand-derived sampling steps.
Applications
- Educational research: estimating school-level effects on student outcomes while accounting for student-level covariates.
- Clinical trials and meta-analysis: pooling treatment effects across study sites or independent studies with site-specific random effects.
- Ecological studies: species abundance models with observations nested within spatial sampling units.
- Longitudinal data: modelling individual growth trajectories with population-level trend and individual random effects.
- Survey research: small-area estimation where administrative units have few respondents and information must be borrowed from adjacent areas.
- Psychometrics: item response theory models with student-level and item-level parameters estimated jointly.
How it works
How it works
The model is specified as a directed probability hierarchy. Observations y_ij at level 1 are governed by group parameters theta_j; those group parameters are themselves drawn from a population distribution governed by hyperparameters phi; and phi receives its own prior. This nesting is the defining feature that separates multilevel MCMC from a flat MCMC run.
Formula
y_{ij} \sim p(y \mid \theta_j), \quad \theta_j \sim p(\theta \mid \phi), \quad \phi \sim p(\phi)Bayes' rule yields a joint posterior over all group-level parameters and hyperparameters. Because the joint posterior across many groups and their shared hyperparameters has no closed form in general, sampling is required. The key property is partial pooling: the posterior of each group parameter is influenced by its own data and by the population distribution, shrinking extreme estimates toward the overall mean.
Formula
p(\theta_1,\ldots,\theta_J, \phi \mid \mathbf{y}) \propto \prod_{j=1}^{J} p(\mathbf{y}_j \mid \theta_j)\, p(\theta_j \mid \phi)\, p(\phi)The conditional formulas describe a Gibbs-type alternation: given the current hyperparameters, each group's parameters are drawn; given those, the hyperparameters are drawn. Modern implementations such as NUTS (No-U-Turn Sampler, used in Stan) instead sample all parameters jointly using gradient information. Gradient-based samplers such as NUTS often mix better than block-wise Gibbs updates in many hierarchies, though performance depends on the posterior geometry.
Formula
\theta_j^{(t+1)} \sim p(\theta_j \mid \mathbf{y}_j, \phi^{(t)}), \quad \phi^{(t+1)} \sim p(\phi \mid \theta_1^{(t+1)},\ldots,\theta_J^{(t+1)})After a warm-up phase, multiple parallel chains are run and convergence is assessed with R-hat (values below 1.01 indicate mixing) and effective sample size. Trace plots for both group-level and population-level parameters should be inspected. Poorly identified hyperparameters, or a funnel-shaped posterior geometry that is common when between-group variance is small, may require reparameterisation such as the non-centred parameterisation.
From the posterior samples, group-specific means and credible intervals, population-level effects, and variance components (between-group vs. within-group variability) are summarised. Posterior predictive checks assess whether the model reproduces key features of the observed data. ICC (intraclass correlation) and partial-pooling weights indicate how much information is shared across groups.
Common pitfalls
- Running only a single chain and trusting the results without verifying convergence via R-hat and trace plots across multiple chains.
- Using centred parameterisation in deep hierarchies without checking, which can lead to severe funnel geometry and poor mixing; compare centred and non-centred parameterisations in Stan or PyMC, checking divergences and R-hat.
- Placing an improper or very diffuse prior on the between-group variance, which can produce an improper or poorly behaved posterior.
- Treating the posterior samples as independent draws when the effective sample size is much smaller than the raw sample count.
- Ignoring posterior predictive checks and assuming the model fits because MCMC converged.
Frequently asked questions
How does Multilevel MCMC differ from running separate MCMC analyses for each group?
Separate analyses ignore the population structure, so each group is estimated using only its own data, and small groups get very uncertain estimates. Multilevel MCMC estimates all groups jointly under a shared population distribution, which regularises small-group estimates by borrowing strength from the rest. The amount of pooling is estimated from the data through the population distribution rather than fixed in advance.
What is non-centred parameterisation and when do I need it?
In the centred form, group parameters theta_j are sampled directly from N(mu, sigma). When sigma is small, the theta_j are tightly constrained and the sampler must navigate a narrow funnel, which can cause poor mixing. The non-centred form reparameterises as theta_j = mu + sigma * z_j and samples the standardised offsets z_j, whose prior does not depend on sigma. This often gives better geometry when group-level data are weak. Neither form is uniformly better: when each group has abundant data, the centred form can mix as well or better. Check divergences and R-hat for either choice, and compare both if sampling problems appear.
How many groups do I need for multilevel MCMC to work well?
There is no universal minimum. Hyperparameters become better identified as the number of groups grows, and with only a few groups the between-group variance is weakly identified and results can be strongly prior-dependent. Whether the number of groups is adequate depends on the data, the group sizes and the priors, so a sensitivity analysis over the hyperpriors is advisable. With very few groups, a fixed-effects model or a strongly informative hyperprior may be considered.
How do I assess whether the multilevel structure is necessary?
Compute the intraclass correlation coefficient (ICC) from the posterior. A near-zero ICC indicates little between-group variability and a flat model may suffice. LOO-CV or WAIC comparison between a flat Bayesian model and the hierarchical model provides a principled predictive criterion for model selection.
Can Multilevel MCMC handle non-normal outcomes?
Yes. The MCMC framework places no restriction on the likelihood: Bernoulli/logistic for binary outcomes, Poisson or negative-binomial for counts, Weibull for survival times, and so on are all straightforward to specify in Stan or PyMC. The hierarchical structure is independent of the distributional form of the observations.
Related methods
Sources
Gelman, A., Carlin, J. B., Stern, H. S., Dunson, D. B., Vehtari, A. & Rubin, D. B. (2013). Bayesian Data Analysis (3rd ed.). CRC Press.
ISBN: 978-1439840955Gelfand, A. E. & Smith, A. F. M. (1990). Sampling-based approaches to calculating marginal densities. Journal of the American Statistical Association, 85(410), 398-409.
Open DOI reference