Skip to main content

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
Constraints arbitrary linear constraints A x = e (R-INLA extraconstr) 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.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pylgm 0.5.0
File Size Uploaded
pylgm-0.5.0.tar.gz 859.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pylgm 0.5.0
File Interpreter ABI Platform
pylgm-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 1.0 MB

Release files / pylgm-0.5.0.tar.gz

Download URL pylgm-0.5.0.tar.gz
Size 859.2 kB
Tags Source
SHA-256 checksum
How to use checksums
0cf051149c258a981a263e19028b6720d9b8e70d901d49c9de19c541687e71ab
BLAKE2b-256 checksum
How to use checksums
e64e2a41f6c92c37b043efcb46595b4affc43ff2b2632c333821b3b66337f431
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 30, 2026.

Transparency log

Release files / pylgm-0.5.0-py3-none-any.whl

Download URL pylgm-0.5.0-py3-none-any.whl
Size 147.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ea047fe491ddba9b992f7fa52073b67e4a0205b99003fa1bced302f651257046
BLAKE2b-256 checksum
How to use checksums
6f09178976da710f317944646df56eb8f18b0f3867e7e9a47a40307e5063e6af
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 30, 2026.

Transparency log

Release history Release notifications | RSS feed

0.6.1

2 release files

0.6.0

2 release files

This release

0.5.0 This release

2 release files

0.4.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page