Abstract
Multilevel models (MLMs) are a central building block of the Bayesian workflow. They enable joint, interpretable modeling of data across hierarchical levels and provide a fully probabilistic quantification of uncertainty. Despite their well-recognized advantages, MLMs pose significant computational challenges, often rendering their estimation and evaluation intractable within reasonable time constraints. Recent advances in simulation-based inference offer promising solutions for addressing complex probabilistic models using deep generative networks. However, the utility and reliability of deep learning methods for estimating Bayesian MLMs remain largely unexplored, especially when compared with gold-standard samplers. To this end, we explore a family of neural network architectures that leverage the probabilistic factorization of multilevel models to facilitate efficient neural network training and subsequent near-instant posterior inference on unseen datasets. We test our method on several real-world case studies and provide comprehensive comparisons to Stan’s gold standard sampler, where possible. Finally, we provide an open-source implementation of our methods to stimulate further research in the nascent field of amortized Bayesian inference.
Introduction
Multilevel models (MLMs)—also known as hierarchical or mixed-effects models—are the workhorse of modern statistics. They allow researchers to account for data nested in groups, such as patients within hospitals or students within schools. While powerful, they present a significant computational tax for traditional Bayesian methods like Markov chain Monte Carlo (MCMC).
As the number of groups increases, MCMC becomes agonizingly slow, often taking days or weeks to run. Furthermore, if new data is acquired or cross-validation is required, the entire sampling process must typically be restarted from scratch. This computational bottleneck limits the complexity of models researchers can use and prevents Bayesian workflows from being deployed in real-time applications. This paper introduces a framework to bypass these limitations through amortized inference.
The ML-NPE Framework
The core contribution of this work is Multilevel Neural Posterior Estimation (ML-NPE). This approach utilizes Normalizing Flows—a class of generative models—to learn the relationship between observed data and latent parameters.
The breakthrough lies in an architecture designed to "mirror" the mathematical factorization of the multilevel model itself. The system is partitioned into two primary components:
- Hierarchical Summary Networks: These networks process raw data of varying sizes. A "local" network compresses data from individual groups, while a "global" network aggregates these summaries into a single representation of the entire dataset.
- Hierarchical Inference Networks: These perform the posterior estimation. A "global" network estimates overarching hyperparameters (e.g., the average effect across all groups), while a "local" network estimates specific parameters for each group (e.g., unique intercepts for specific sub-populations).
By training on simulated data, the neural network learns to "invert" the model. Once trained, the network can ingest a new dataset and produce a full posterior distribution in a fraction of a second, effectively amortizing the cost of inference.
Empirical Evaluation
The authors validated ML-NPE across three distinct real-world scenarios:
- Air Passenger Traffic: An autoregressive time-series model predicting travel between 16 European countries and the US, accounting for economic covariates like GDP and household debt.
- Diffusion Decision Model (DDM): A foundational cognitive science model used to infer latent decision-making processes from reaction time data.
- Hand-Drawn Digits (EMNIST): A high-dimensional task where the "simulator" is a pre-trained generative network. The goal was to infer individual handwriting styles (slant, height, etc.) from images of digits.
Key Results and Insights
Accuracy and Shrinkage
In comparisons with Stan (the "gold standard" for Bayesian inference), ML-NPE produced nearly identical posterior distributions. Crucially, it correctly captured "shrinkage"—the statistical phenomenon where group-level estimates are pulled toward the global average, a hallmark of well-calibrated multilevel modeling.
Computational Efficiency
While ML-NPE requires an upfront training phase (e.g., ~1 hour for the DDM model), its inference speed is orders of magnitude faster than MCMC. For the air traffic model, Stan required approximately 8 seconds per run, while ML-NPE performed the same task in less than a millisecond. This speed enables previously impossible workflows, such as Leave-One-Group-Out (LOGO) cross-validation, which requires refitting the model dozens of times. With ML-NPE, this process takes seconds rather than hours.
Handling Intractable Likelihoods
Unlike traditional tools that require a closed-form mathematical likelihood, ML-NPE can operate with "black-box" simulators (like the EMNIST digit generation task) where the likelihood is analytically unavailable. This expands the reach of Bayesian analysis to complex simulation-based models.
Conclusion and Future Work
The primary trade-off of ML-NPE is the upfront simulation and training cost. If a researcher only plans to analyze a single dataset once, traditional MCMC remains more efficient. However, ML-NPE is transformative for scenarios requiring repeated analysis of many datasets or intensive model checking.
Currently, the framework is optimized for two-level hierarchies. Extending this to "deep" hierarchies (e.g., students within classrooms within schools) is a primary avenue for future research. Additionally, for models with extremely expensive simulators, sequential neural methods may be integrated to focus training on the most relevant parameter spaces. The implementation is available as part of the open-source BayesFlow library.
Summary updated