MetaBeta
Bayesian inference for GLMMs (generalized linear mixed-effects models) in under a second:
- Full posterior in one call for Gaussian, Bernoulli and Poisson outcomes: fixed effects, random effects, and their standard deviations (SDs) and correlations.
- Priors as input: you can change them without retraining, fit several at once, and compare models using Bayes factors.
- Asymptotically exact: Metropolis-Hastings refines the networks' posterior samples against the exact unnormalized posterior.
- Diagnostics included: every fit reports diagnostics and suggests a remedy.
- A familiar workflow: lme4-style tables, per-group effects, pair plots and posterior predictive checks.
Installation
pip install metabeta
The pretrained checkpoints download from Hugging Face on first use.
For development:
git clone https://github.com/adkipnis/metabeta && cd metabeta && uv sync
Quick start
Fit lme4's sleepstudy: reaction times of 18 subjects over 10 days of sleep restriction.
import pandas as pd
from metabeta import Api
df = pd.read_csv('https://vincentarelbundock.github.io/Rdatasets/csv/lme4/sleepstudy.csv')
mb = Api.from_pretrained('gaussian')
result = mb.sample(df, formula='Reaction ~ Days + (Days | Subject)')
print(mb.posteriorSummary(result))
Formula: Reaction ~ Days + (Days | Subject)
n = 180 m = 18
...
Fixed Effects:
| | Mean | SD | 2.5% | 50.0% | 97.5% | P(>0) | Contr. |
|-----------|---------|-------|---------|---------|---------|---------|----------|
| Intercept | 251.276 | 8.046 | 235.865 | 251.166 | 267.935 | 1.000 | 0.999 |
| Days | 10.434 | 1.653 | 7.267 | 10.485 | 13.676 | 1.000 | 0.999 |
Standard Deviations:
| | Mean | SD | 2.5% | 50.0% | 97.5% |
|-----------|--------|-------|--------|---------|---------|
| Intercept | 29.938 | 8.059 | 17.744 | 29.099 | 47.685 |
| Days | 6.368 | 1.472 | 3.936 | 6.194 | 9.584 |
| Residual | 25.752 | 1.535 | 22.652 | 25.714 | 28.829 |
...
draws = 1000 acceptance = 0.78 min ESS = 456 PSIS k̂ = 0.240 MAP z = 0.5 R² = 0.827
- Units: ms, and ms per day for
Days(lme4: 251.4 and 10.47). - Last line: the diagnostics are explained in the FAQ.
- More:
mb.rfxSummary(result)prints each subject's random effects, andmb.plotParameters(result)visualizes posterior draws. The tutorials coverposteriorDraws,groupDraws,posteriorPredictiveandbayesFactor.
Tutorials
| Notebook | Content | |
|---|---|---|
| 01-quickstart | First fit: summaries, plots and diagnostics | |
| 02-families | Bernoulli and Poisson outcomes | |
| 03-priors | Custom priors and Bayes factors |
How it was built
Simulation (figure, top)
- Sizes: the numbers of predictors d, random effects q, groups m and rows per group ni are drawn first.
- Priors: the prior families and their scales are drawn next.
- Parameters: the fixed effects β, random-effect SDs σ and correlations R are drawn from these priors.
- Predictors: X is sampled from synthetic tables, built from random structural causal models as in TabPFN/TabICL, or subsampled from hundreds of real tabular datasets.
- Outcomes: y is drawn from the GLMM, given X and the parameters.
Training (figure, bottom)
- Summaries: Σl condenses all rows per group into a vector, and Σg condenses these vectors into one summary s. Both ignore the order of rows and groups.
- Augmentation: efficient analytical estimates and the prior join the summaries.
- Posterior: normalizing flows turn random noise u into posterior draws. Πg draws β, σ and R from s; Πl draws each group's αi from its summary and a draw of Πg.
- Objective: all networks are trained end-to-end to optimize the probability of the true parameters under the proposed posterior.
A GLMM fit is then a forward pass through the trained networks. Metropolis-Hastings refines its draws to grant the estimated posterior asymptotic exactness.
FAQ
What can MetaBeta fit?
- Models: Gaussian, Bernoulli (0/1) and Poisson GLMMs with one grouping factor.
- Data: 5 to 200 groups, 5 to 150 rows per group, at most 3,000 rows.
- Effects: at most 16 fixed and 5 random effects, intercepts included.
- Random slopes: each must also be a fixed effect.
- Enough groups: at least 4 more groups than fixed effects, and than random-effect variances and covariances.
- Enough rows: at least 2 more rows per group than random effects.
- Formulas: additive lme4 syntax, such as
y ~ x1 + x2 + (1 + x1 | g). - Categories: string and categorical columns are dummy-coded, with the most frequent level as the reference (R uses the first).
- Currently not supported:
||,/, interactions (:,*), functions (log(),factor(),C()), offsets and binomial trials. Transform the columns in the DataFrame instead; the error message says how.
Do I need a GPU?
No. A fit takes 0.2 to 1 second on a laptop CPU, and about 0.1 seconds on a fast GPU. Colab's
free runtimes are slower: one to a few seconds on CPU or T4. To use a GPU, pass device='cuda' to
Api.from_pretrained.
What do the diagnostics mean?
They are in the summary's last line and in result.safeguards:
acceptance: the share of the networks' draws that Metropolis-Hastings accepts.min ESS: the smallest effective sample size (ESS).PSIS k̂: how well the networks' draws match the posterior, by Pareto-smoothed importance sampling (PSIS); lower is better.MAP z: the distance between the posterior mean and the maximum a posteriori (MAP) estimate, in posterior SDs.R²,AUCorDeviance, by family: how well the posterior predicts the data (inresult.diagnostics).
sample warns when the acceptance, the ESS or MAP z crosses its threshold.
When should I fall back to NUTS?
When sample still warns after you apply its suggested remedy, e.g. more draws or
random-walk moves (random_walk=True). 02-families compares a Poisson fit with NUTS.
Contributing
Issues and pull requests are welcome; see
CONTRIBUTING.md.
Citing
@misc{kipnis.2026,
title = {Prior-Amortized In-Context {Bayesian} Inference for Generalized Linear
Mixed-Effects Models},
author = {Kipnis, Alex and Binz, Marcel and Schulz, Eric},
year = {2026},
eprint = {2609.24422},
archivePrefix = {arXiv},
primaryClass = {cs.LG},
url = {https://arxiv.org/abs/2609.24422}
}
All versions share the DOI 10.5281/zenodo.23458113.
License
- Code: Apache-2.0.
- Weights: CC BY-NC-SA 4.0.
Metadata
Release files for metabeta 0.6.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| metabeta-0.6.1.tar.gz | 801.1 kB | With provenance | Details for metabeta-0.6.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| metabeta-0.6.1-py3-none-any.whl | Python 3 | none | any | Details for metabeta-0.6.1-py3-none-any.whl |
Total release size: 1.2 MB
Release files / metabeta-0.6.1.tar.gz
| Download URL | metabeta-0.6.1.tar.gz |
|---|---|
| Size | 801.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5f6cc64b5f5fc73ba1116e85b41e75de6e612c53134c0e80c8f5de7bde9b6ac6
|
|
BLAKE2b-256 checksum How to use checksums |
8134f65300bf614bcd740f8314f1f8b0d65ced3ae17b1c5b00f28c58d7a35a4d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 7, 2026.
Transparency logRelease files / metabeta-0.6.1-py3-none-any.whl
| Download URL | metabeta-0.6.1-py3-none-any.whl |
|---|---|
| Size | 358.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f1fac4ffcfd5c77e31e2e741ed2abeab1b401fe0839831f569dcaf88495a263c
|
|
BLAKE2b-256 checksum How to use checksums |
de68948fa1f8af74994e72ef681a7df61a9d2f9a8b162b99513dd6e3b734e4db
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 7, 2026.
Transparency logSecurity for metabeta 0.6.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for metabeta-0.6.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 7, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.