glmm
glmm: mixed models from an R-style formula, with NumPy as the only dependency.
glmm fits ordinary least squares, generalized linear models, linear mixed models and generalized linear mixed models from an R-style formula. It is the Python package of the glmm engine, which also serves Rust and R.
The idea
- Accuracy first. glmm reaches the same log-likelihood as lme4, glmmTMB, MixedModels.jl and GLMMadaptive, or a better one.
- Multi-solver. Each model gets a method that suits it. Least squares uses a closed form, and GLMs use IRLS. Mixed models use BFGS where glmm has a cheap exact gradient, and BOBYQA, which needs no gradient, elsewhere.
- Fast. glmm is faster than these four packages on every model in the speed tests, and it uses little memory. Part of the time saved goes to extra checks during a fit, which catch hard models where a search would stop too early.
More in the project README.
Install
pip install glmm
Requires Python 3.10+. The only runtime dependency is NumPy. glmm also runs in the browser under Pyodide: a Pyodide wheel is attached to each GitHub release.
Validation
glmm is checked on 947 test models before every release. They cover the Gaussian, binomial, Poisson, Gamma and negative binomial families, random intercepts, correlated slopes, nested and crossed groupings, and data from 60 to 30,000 rows. Each model is also fitted by lme4, glmmTMB, MixedModels.jl and GLMMadaptive, where they support it. glmm is compared with the best of their results, not with one chosen package. If glmm reaches a worse log-likelihood than that best result, the release fails. If its estimates differ from the other packages, the difference passes only once it is explained in writing.
Standard errors of mixed models come from the exact second derivatives of the likelihood, not from a finite-difference approximation. On the test models they differ from a high-precision lme4 run by at most 0.002% (relative).
glmm was also stress-tested on many hard and borderline models. On such models
it returns a result with flags that say what happened, instead of only printing
a warning. A variance that falls to zero is set to exactly zero and flagged. A
redundant column is dropped and marked, as in lme4. When a fit fails, the
converged flag says so. glmm does not crash.
The package versions, the checks and how to rerun them are in
validation.md.
Multi-solver paradigm
glmm combines several optimizers for mixed models. Where it has a cheap exact gradient, it uses BFGS. Elsewhere it uses BOBYQA, which needs no gradient. BOBYQA also refines the BFGS result and takes over when BFGS fails.
On larger GLMMs, a fast approximate pass first finds a good starting point, and the full search starts from there. When the main search does not converge, the fit tries a second search strategy from the same start and keeps the better answer.
The linear algebra also uses more than one method. Common model shapes use small dense blocks, one per group. Larger or more complex designs go to a sparse solver instead of being refused. Given the same variance parameters, both return the same answer. The choice affects speed only.
Speed
glmm moves as little data as it can. One pass over the data builds a small summary per group, and every later step of the search works on those summaries. The cost of each step therefore grows with the number of groups, not the number of rows.
glmm is also designed for refitting the same model many times. Its working memory depends only on the shape of the model. So refitting the same model on new data, as in a power simulation or a bootstrap, needs no new memory. Each refit can also start from the previous answer.
The search also needs few steps. Its settings were tuned on the 923 test models and kept only where they cut the number of steps without changing any result. With a cheap exact gradient it needs even fewer.
Each of these choices, and how it differs from lme4 and MixedModels.jl, is in
glmm-design.md.
Quick start
data is any data table: a dict of columns, or a pandas / polars DataFrame.
import glmm
# OLS: fixed effects only
fit = glmm.fit(data, "y ~ x1 * x2")
# LMM: correlated random intercept and slope (REML)
fit = glmm.fit(data, "y ~ x1 + (1 + x1 | subject)")
# The same LMM by maximum likelihood, as lme4's REML = FALSE
fit_ml = glmm.fit(data, "y ~ x1 + (1 + x1 | subject)", reml=False)
# GLMM: binomial with a probit link, 7-node adaptive quadrature
fit = glmm.fit(data, "passed ~ x1 + (1 | school)", "binomial", link="probit", nagq=7)
fit.summary() # coefficient table + variance components
fit.beta, fit.se # estimates and standard errors
fit.coef_df, fit.confint() # t-test df (Satterthwaite on an LMM), intervals
fit.converged, fit.singular # result flags
glmm.anova(fit) # tests of the fixed terms (Type III)
glmm.compare(data, "y ~ x1", "y ~ x1 + (1 | subject)") # two nested models, fitted and compared
glmm.pairwise(fit, "f") # pairwise comparisons of the levels of factor f (Holm)
fit.predict(new_data) # predictions on new rows
Documentation
- Python tutorial:
every option, the
Fitobject, and warm starts. - Worked examples on real datasets.
- Coming from statsmodels and coming from lme4.
- What the formula accepts.
- Tests of fixed terms and model comparisons.
- Fixes for common errors.
- All documentation.
Citation
If you use glmm in research, please cite:
Lenartowicz, P. (2026). glmm: Mixed-model fitting in Rust, Python and R [Computer software]. https://github.com/pawlenartowicz/glmm
@software{glmm2026,
author = {Lenartowicz, Pawe{\l}},
title = {{glmm}: Mixed-Model Fitting in Rust, Python and R},
year = {2026},
url = {https://github.com/pawlenartowicz/glmm}
}
License
LGPL-3.0-or-later.
Paweł Lenartowicz — Freestyler Scientist · GitHub · ORCID
Metadata
Release files for glmm 0.8.0
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 |
|---|---|---|---|---|
| glmm-0.8.0.tar.gz | 2.5 MB | With provenance | Details for glmm-0.8.0.tar.gz |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| glmm-0.8.0-cp310-abi3-win_amd64.whl | CPython 3.10 | abi3 | Windows x86-64 | Details for glmm-0.8.0-cp310-abi3-win_amd64.whl |
| glmm-0.8.0-cp310-abi3-manylinux_2_28_x86_64.whl | CPython 3.10 | abi3 | Linux glibc 2.28+ x86-64 | Details for glmm-0.8.0-cp310-abi3-manylinux_2_28_x86_64.whl |
| glmm-0.8.0-cp310-abi3-macosx_11_0_arm64.whl | CPython 3.10 | abi3 | macOS 11.0+ ARM64 | Details for glmm-0.8.0-cp310-abi3-macosx_11_0_arm64.whl |
Total release size: 14.8 MB
Release files / glmm-0.8.0.tar.gz
| Download URL | glmm-0.8.0.tar.gz |
|---|---|
| Size | 2.5 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e61aadbe4badf415e77efcc46fd81de50399c52af8e5c57997f4d93b8899c06a
|
|
BLAKE2b-256 checksum How to use checksums |
8ebdae90ab84e40976751e265c39c5411b1a8e50779117480dc97ada51c34056
|
| 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 1, 2026.
Transparency logRelease files / glmm-0.8.0-cp310-abi3-win_amd64.whl
| Download URL | glmm-0.8.0-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 4.2 MB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
f1a80a08ab4fd1bf0b8204860660bb9ff83901de6c129adf282684348782be09
|
|
BLAKE2b-256 checksum How to use checksums |
2d80d66497bdaed15ae719c950a76cc51bb6d0ee6d8a9340838302b9a4ebf8f0
|
| 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 1, 2026.
Transparency logRelease files / glmm-0.8.0-cp310-abi3-manylinux_2_28_x86_64.whl
| Download URL | glmm-0.8.0-cp310-abi3-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 4.5 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
0cdcaa67f2a6c79b2d640c37d38688e7247446c7c7b76b0020c483d91cd053ea
|
|
BLAKE2b-256 checksum How to use checksums |
5eb09366eca9d8e96b944416809073cd7bbe3630cbc0162b91ae42d50cc73efa
|
| 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 1, 2026.
Transparency logRelease files / glmm-0.8.0-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | glmm-0.8.0-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 3.5 MB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
0678a217723a0245ef25b98448062e3e9a92d701a082aa2136c1bbfb3c5a83b5
|
|
BLAKE2b-256 checksum How to use checksums |
44cc236446131ae8c125f3b6323768c4e5e0e48ed936e3576538255811704e54
|
| 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 1, 2026.
Transparency logSecurity for glmm 0.8.0
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
All 4 files in this release have been uploaded with provenance metadata.
Attestation for glmm-0.8.0.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 1, 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.