- Introduced by
- Ranganath, Altosaar, Tran, Blei (hierarchical VI formalization, 2016); Blei et al. (VI framework, 2017)
- Year
- 2016
- Type
- approximate Bayesian inference
- Family
- Bayesian / computational
What does it do?
Multilevel variational inference (MLVI) fits hierarchical models by replacing MCMC sampling with optimization: it selects the member of a tractable family of distributions that lies closest to the posterior, measured by maximizing the evidence lower bound (ELBO).
The family follows the grouped structure of the model, with global parameters beta shared across groups and local parameters z_g specific to each group g, so updates can be organized group by group. It is aimed at grouped data where exact inference or MCMC is slow.
The intuition behind the method
In a multilevel model, the joint posterior over group-level effects and global parameters is complex and usually has no closed form. Variational inference replaces posterior sampling with optimization: it chooses a distribution from a family that is easy to work with, such as a factored Gaussian, and tunes it to be as close as possible to the true posterior. Closeness is measured by Kullback–Leibler divergence, and maximizing the ELBO is equivalent to minimizing that divergence. The multilevel structure is used by building the variational family along the same grouping, so local parameters can be updated group by group while shared parameters are updated globally. The output is a fitted approximate posterior, not a set of exact posterior draws.
History
Mean-field variational inference and its use in Bayesian statistics are reviewed by Blei, Kucukelbir and McAuliffe (2017). That review frames inference as an optimization problem in which a family of densities is posited and the member closest to the target is found by minimizing Kullback–Leibler divergence. It also covers the treatment of exponential-family models and a stochastic-optimization variant for massive data. Multilevel forms of variational inference build on this general framework.
When to use it
Choose MLVI when observations are grouped or nested (students within schools, patients within hospitals, repeated measures within subjects), the model is a continuous or mixed-type hierarchical model, and the data or number of groups are too large for MCMC to be practical. It suits exploratory work and screening many candidate models, where approximate posteriors are sufficient for comparison. Do not use it as the final inference when accurate uncertainty for variance components or tail probabilities matters and MCMC is feasible. In small samples, approximation error can dominate, so MCMC, or a check against it, is preferable. A practical check is to fit the same model with MCMC on a representative subset of the data and compare posterior means and standard deviations for the fixed effects and variance components. Larger discrepancies in the variance components are the main warning sign, because these are where the approximation most often understates uncertainty. What counts as an acceptable discrepancy depends on the decision the analysis supports and is not fixed by a general rule.
Limitations and considerations
- Factorized approximations assume weaker dependence than the true posterior often has; where global and group-level parameters are strongly correlated, the approximation is biased, and this matters most for variance components.
- Variational approximations of this kind often underestimate posterior variance, which affects random-effect standard deviations in particular.
- The ELBO is generally non-convex, so optimization may reach a local optimum that is not the best available approximation.
- ELBO convergence does not certify an accurate posterior, and MCMC-style diagnostics such as chain mixing do not apply, so checking fit is harder.
- Posterior predictive checks can still be run from variational draws, but they may miss misfit that the approximation itself hides.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Replaces MCMC sampling with optimization, so there are no chains to mix and no long sampling runs to store.
- The conditional structure of the family (groups conditionally independent given beta) lets each group's local updates be computed separately, which is what makes mini-batching over groups possible.
- Convergence is monitored through the ELBO trace, a single objective to inspect; a plateau, however, does not certify that the approximation is accurate (see limitations).
- Returns a full approximate posterior over all parameters, so uncertainty can be reported for fixed effects, group-level effects and variance components.
Applications
- Educational data analysis: estimating school- and district-level effects when student achievement datasets are large and MCMC becomes costly.
- Clinical research: fitting patient-within-clinic hierarchical models across hospital networks where data volume makes MCMC slow.
- Natural language processing: topic models with document-level and corpus-level latent variables, which can be fitted with variational methods.
- Ecological studies: species distribution models with spatial groupings, where the number of sites makes sampling slow.
- Online learning systems: sequential updating of multilevel posteriors as grouped data arrive in batches.
- Psychometric models: item response models with person and item random effects, where large testing datasets make MCMC slow.
How it works
How it works
Write the full generative model with global parameters beta shared by all groups and local parameters z_g specific to group g. The joint density factorizes into a prior on beta, a term for each group-level z_g given beta, and an observation term for each individual i in group g. This conditional structure is what the later steps exploit.
Formula
p(y, z, \beta) = p(\beta) \prod_{g=1}^{G} p(z_g \mid \beta) \prod_{i \in g} p(y_i \mid z_g, \beta)Use q(z, beta) = q(beta) times the product over groups of q(z_g | beta). Each local factor is conditioned on the global parameters, so the dependence between local and global parameters is retained, while groups are treated as conditionally independent given beta. A fully factorized mean-field family, which does not condition q(z_g) on beta, drops this dependence. How much of the posterior correlation between global and group-level parameters the family can represent therefore depends on this choice. Dropping that dependence can contribute to variance underestimation, as can mean-field approximations in general, and the size of the effect depends on the model and the data.
Formula
q(z, \beta) = q(\beta) \prod_{g=1}^{G} q(z_g \mid \beta)The ELBO is the objective to maximize: the expected log joint density under q minus the expected log density of q. It is a lower bound on the log marginal likelihood, and increasing it reduces the Kullback–Leibler divergence between q and the true posterior.
Formula
\mathcal{L}(q) = \mathbb{E}_q[\log p(y, z, \beta)] - \mathbb{E}_q[\log q(z, \beta)]Maximize the ELBO by stochastic gradient ascent or coordinate ascent variational inference (CAVI). Stochastic variants update using mini-batches of groups, which is what allows large numbers of groups to be processed. Natural-gradient updates, which account for the geometry of the variational family, are an alternative for the same objective.
After optimization, the variational parameters (the means and variances of the approximating factors) are read off as posterior summaries. Fixed effects, group-level effects and variance components are summarized from the fitted q, and approximate credible intervals are derived from its variance. These intervals carry the approximation error described under limitations.
Common pitfalls
- Reading variational standard deviations for random effects as if they matched MCMC posterior standard deviations; they are often too narrow.
- Using a fully factorized family when the posterior correlates global parameters (such as a group-level variance) with group effects, which leads to poor approximations.
- Stopping optimization before the ELBO has plateaued; with stochastic updates the ELBO trace is noisy, so judge convergence on a smoothed trace.
- Skipping a check against MCMC on a representative subset of the data before relying on the approximate posterior.
- Comparing ELBO values from models fitted to different data or likelihoods as evidence of better fit; the ELBO bounds the log evidence of one specific model, and the size of the gap depends on the variational family.
Frequently asked questions
How does multilevel variational inference differ from standard variational inference?
Multilevel VI differs in how the variational family is built: it follows the model's grouping, so each local parameter z_g receives a factor conditioned on the global parameters beta. This allows local updates to be computed group by group and, under stochastic optimization, mini-batches of groups to be used, as stochastic variants of VI are described for large datasets in Blei et al. (2017). Whether the resulting approximation is accurate depends on how much of the local-global dependence the chosen family retains.
Does variational inference give accurate uncertainty estimates for random-effect variances?
Often not. Mean-field VI is known to underestimate posterior variance, and this problem is particularly pronounced for variance components (random-effect standard deviations) in multilevel models. When accurate uncertainty for these quantities is needed, MCMC or a richer variational family (e.g., normalizing flows) should be used.
How do I know if the variational approximation is adequate?
The most reliable check is to run full MCMC on a representative subset of data and compare posteriors. Within the VI workflow, monitor ELBO convergence, examine posterior predictive checks using samples from the variational distribution, and test sensitivity to the choice of variational family.
Can multilevel variational inference handle crossed random effects?
Yes, but with extra care. Crossed designs (e.g., items and subjects both as random effects) break the simple nested factorization, because local parameters are no longer conditionally independent given a single grouping. The variational family must be designed for the resulting dependencies, and naive mean-field approximations may perform poorly.
Is multilevel variational inference available in standard software?
Several general-purpose probabilistic programming systems provide variational inference, but support for hierarchical models, specific variational families and grouping structures varies between them. Check the documentation of the tool you plan to use to confirm that it supports the family and grouping structure you need.
Related methods
Sources
Blei, D. M., Kucukelbir, A., & McAuliffe, J. D. (2017). Variational inference: A review for statisticians. Journal of the American Statistical Association, 112(518), 859-877.
Open DOI referenceRanganath, R., Altosaar, J., Tran, D., & Blei, D. M. (2016). Operator variational objectives. Advances in Neural Information Processing Systems, 29. Curran Associates.
Open publication reference