pyLGM
General-purpose latent Gaussian models for Python — the model class behind INLA. Fit fixed effects, random effects, temporal (RW/AR1) and spatial (CAR) structure under Gaussian, Poisson, or Bernoulli likelihoods, from a Pandas (or Spark) DataFrame, with exact-Gaussian and Laplace inference engines, empirical Bayes / MAP-II hyperparameter estimation, and INLA-style posterior integration.
Install
pip install pylgm
pip install "pylgm[spark]" # optional: Spark data boundary
Requires Python ≥ 3.11.
30-second example
A Poisson model with a per-region random intercept, fit with the Laplace engine:
import pandas as pd
from pylgm import Fixed, IID, LGM, Poisson
# Counts of events per region over time, with a covariate x.
frame = pd.DataFrame({
"region": ["north", "north", "north", "south", "south", "south"],
"time": [1, 2, 3, 1, 2, 3],
"x": [0.0, 0.5, 1.0, 0.0, 0.5, 1.0],
"count": [3, 5, 8, 2, 3, 5],
})
model = LGM(
response="count",
likelihood=Poisson(), # canonical log link
predictor=Fixed("1 + x") # fixed effects
+ IID("region", index="region", precision=2.0), # random intercept per region
panel=("region",),
time="time",
)
result = model.fit(frame, engine="laplace")
print("fitted_mean:", result.fitted_mean.round(3).tolist())
# fitted_mean: [3.254, 4.986, 8.15, 2.201, 3.373, 5.513]
The same model can be declared in YAML and loaded with pylgm.config.load_model.
See the general LGM example, which fits the
same data through both the Python and YAML frontends, and the other 13 runnable
scripts under examples/.
What's in the box
| Area | What you get | Docs |
|---|---|---|
| Likelihoods | Gaussian (exact), Poisson & Bernoulli (Laplace) | likelihoods |
| Effects | Fixed, IID, RW1/RW2, stationary AR1 |
effects |
| Spatial | Besag (ICAR), ProperCAR (with ρ), BYM2 (with φ) |
spatial effects |
| Hyperparameters | Empirical Bayes (type-II ML), MAP-II priors, bounds | empirical bayes |
| Integration | INLA-style grid quadrature, simplified/full-Laplace marginals, DIC/WAIC/CPO/PIT | INLA |
| Prediction | fit-row and out-of-sample result.predict(new_data) |
prediction |
| Data boundary | Pandas, or Spark / Databricks | spark |
Documentation
Full docs: https://ardea00.github.io/pylgm/ — or browse the
docs/ folder. Start with the index.
Scope and roadmap
pyLGM 0.3 is a bounded foundation release. What is and isn't in it, and where it's going, are documented in the roadmap and the internals / release policy page.
Development
See docs/development.md. License: MIT.
Release files for pylgm 0.4.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 | |
|---|---|---|---|
| pylgm-0.4.0.tar.gz | 631.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pylgm-0.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 739.2 kB
Release files / pylgm-0.4.0.tar.gz
| Download URL | pylgm-0.4.0.tar.gz |
|---|---|
| Size | 631.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cce0deb2f742c5d955d80e7bd140faaac4c9a6727dd6e3ed92134ddd36607c1c
|
|
BLAKE2b-256 checksum How to use checksums |
911ab668a8140251a245e02fa92afbf85c5aaa4af4bd96403c5f3f4b96a2eb69
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Aug 26, 2026.
Transparency logRelease files / pylgm-0.4.0-py3-none-any.whl
| Download URL | pylgm-0.4.0-py3-none-any.whl |
|---|---|
| Size | 107.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0be658b858e12ab7c57e5edbc9cea6983ca6f1a4e10da37aa7bb6d2a82a5667f
|
|
BLAKE2b-256 checksum How to use checksums |
43109cac487c35af0b7ee31f8bc8a0182a9b82d138c91169d93e852daa58d3c2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Aug 26, 2026.
Transparency log