[Paper Review] Bambi: A simple interface for fitting Bayesian linear models in Python
Bambi provides a Python-based, formula-driven interface for fitting Bayesian generalized linear multilevel models on top of PyMC, enabling easy specification, fitting, diagnostics, and predictions, including regression, logistic, and hierarchical models.
The popularity of Bayesian statistical methods has increased dramatically in recent years across many research areas and industrial applications. This is the result of a variety of methodological advances with faster and cheaper hardware as well as the development of new software tools. Here we introduce an open source Python package named Bambi (BAyesian Model Building Interface) that is built on top of the PyMC probabilistic programming framework and the ArviZ package for exploratory analysis of Bayesian models. Bambi makes it easy to specify complex generalized linear hierarchical models using a formula notation similar to those found in R. We demonstrate Bambi's versatility and ease of use with a few examples spanning a range of common statistical models including multiple regression, logistic regression, and mixed-effects modeling with crossed group specific effects. Additionally we discuss how automatic priors are constructed. Finally, we conclude with a discussion of our plans for the future development of Bambi.
Motivation & Objective
- Promote widespread adoption of Bayesian methods by lowering the barrier to fitting GLMMs.
- Provide an intuitive, formula-based interface similar to R’s lme4 for specifying complex models.
- Integrate with PyMC and ArviZ to enable efficient sampling, diagnostics, and visualization of Bayesian models.
- Demonstrate versatility through examples: multiple regression, logistic regression, and hierarchical models with random effects.
- Discuss default priors, inference workflows, and future development of the Bambi package.
Proposed method
- Introduce a Python package (Bambi) built on PyMC and ArviZ for Bayesian GLMMs.
- Use a formula interface (similar to R) to specify fixed and random effects with a Model class.
- Employ adaptive dynamic Hamiltonian Monte Carlo for posterior sampling and multiple chains for diagnostics.
- Provide default priors when not specified, with mechanisms to inspect priors via plot_priors().
- Support various families (Gaussian, Bernoulli, etc.) and link functions via a Family class.
- Enable posterior predictive checks and predictions through a .predict() method and ArviZ visualizations.

Experimental results
Research questions
- RQ1How can Bayesian generalized linear multilevel models be specified conveniently in Python using a formula-like interface?
- RQ2What priors are used by default in Bambi, and how can users customize them?
- RQ3How does Bambi facilitate model fitting, diagnostics, and posterior predictive checks for different model families (e.g., Gaussian, Bernoulli)?
- RQ4Can users perform complex hierarchical models with crossed random effects and inspect model outputs easily?
- RQ5What is the workflow for making in-sample and out-of-sample predictions with posterior uncertainty?
Key findings
- Bambi enables quick specification and fitting of GLMMs with sensible defaults and a familiar formula syntax.
- The package leverages PyMC’s adaptive dynamic Hamiltonian Monte Carlo to sample from the joint posterior.
- Users can inspect priors, diagnostics, and posterior summaries via ArviZ, including trace plots and summary statistics.
- The .predict() function allows generating posterior mean predictions and posterior predictive samples for new data.
- Hierarchical models with multiple random effects (intercepts and slopes) can be specified and fit with custom priors.
- Examples demonstrate regression, logistic regression, and crossed random effects, illustrating both usability and modeling flexibility.

Better researchstarts right now
From reading papers to final review, dramatically reduce your research time.
No credit card · Free plan available
This review was created by AI and reviewed by human editors.