Skip to main content

Linear-regression family OLS / GLM / LMM / GLMM — Python port of the glmm crate

Project description

glmm

Linear-regression family — OLS → GLM → LMM → GLMM — in pure Rust, with a two-name Python API.

License: GPL-3.0-or-later

Fits fixed-effect and mixed (random-intercept / random-slope) models for Gaussian, Binomial (logit/probit), Poisson, Gamma, and Negative-Binomial outcomes. The numerics are the glmm Rust crate — no BLAS/LAPACK system dependency, no unsafe, validated against R/lme4 and Julia/MixedModels.jl goldens.

Install

pip install glmm

Requires Python 3.10+. The only runtime dependency is NumPy.

One call

You hand fit a data table and an R-style formula. It parses the formula against the table's columns, builds the design matrix, fits, and returns a Fit. There is no model object to construct.

import glmm

data = {
    "y":     [1.02, 1.05, 1.11, 1.13, 1.21, 1.24, 1.30, 1.33, 1.42, 1.44, 1.51, 1.53],
    "x1":    [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1],
    "group": ["a", "a", "b", "b", "c", "c", "d", "d", "e", "e", "f", "f"],
}

# y ~ x1 + (1 | group) — Gaussian, random intercept.
fit = glmm.fit(data, "y ~ x1 + (1 | group)")

assert fit.converged
fit.summary()   # prints the coefficient table (and returns it as a string)

The public surface is exactly two names: glmm.fit and glmm.Fit. Families, links, and knobs are string or scalar arguments, not types.

data is documented as a dict[str, array-like], but anything column-addressable works — pandas / polars DataFrame, pyarrow Table — by duck-typing, so there is no dataframe dependency.

Model routing

Routing is inferred from the formula and family — fixed-only means OLS/GLM, adding a (… | g) term makes it LMM/GLMM.

family default link other links fixed-only with (… | g)
gaussian identity OLS LMM
binomial logit probit GLM GLMM
poisson log GLM GLMM
gamma log inverse GLM GLMM
negativebinomial log GLM GLMM
fit = glmm.fit(data, "s ~ x1 + (1 | group)", "binomial", link="probit", nagq=7)

The formula follows R conventions: * desugars to main effects + interaction, A/B to nesting, (1 + x | g) is a correlated random intercept + slope, and additional (… | g2) terms add crossed or nested grouping factors. Treatment contrasts (R's default) code the factors: the base is the column's first level, so a pandas.Categorical is fit against the first category you declare, and a plain string column — which declares no order — is sorted lexicographically, as R's factor() does.

Not yet implemented

Four combinations have an approved design but no kernel support, and raise a clean NotImplementedError: family="inversegaussian", link="cloglog", quasi-likelihood dispersion= on binomial/poisson, and a float init_theta= seed (only the default init_theta=None cold start is supported).

Documentation

Full walkthrough — every knob, the Fit object, and warm starts: TUTORIAL-PYTHON.md.

The algorithm map (dispatch graph, solver paths, tuning knobs) is traced to code in documentation/algorithms.md.

License

GPL-3.0-or-later.


Paweł LenartowiczFreestyler Scientist · GitHub · ORCID

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

glmm-0.1.0.tar.gz (603.7 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

glmm-0.1.0-cp310-abi3-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.10+Windows x86-64

glmm-0.1.0-cp310-abi3-manylinux_2_28_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ x86-64

glmm-0.1.0-cp310-abi3-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

Details for the file glmm-0.1.0.tar.gz.

File metadata

  • Download URL: glmm-0.1.0.tar.gz
  • Upload date:
  • Size: 603.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for glmm-0.1.0.tar.gz
Algorithm Hash digest
SHA256 17ac3afcd7536ca2e763ac5e2537ad69957e61b7c4fa85d2f82ba01bc7587602
MD5 18adf8313788d4cbaeba643074ece9e5
BLAKE2b-256 5a96f2029f0c794183d5569aeae597b56df401e567d7375ac26ba9fc7e1ecd67

See more details on using hashes here.

Provenance

The following attestation bundles were made for glmm-0.1.0.tar.gz:

Publisher: release.yml on pawlenartowicz/glmm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file glmm-0.1.0-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: glmm-0.1.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 1.8 MB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for glmm-0.1.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 d8e32c3e28cf86431182d4fad585bb38dedb8ab91aed03f072d4ab17e9521f89
MD5 54e0ccec41c43da6540930d017f514a9
BLAKE2b-256 5921a17ec8d66ea5a577ed2c3ee4407872fce7b77ae888ff912430d9d7e261e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for glmm-0.1.0-cp310-abi3-win_amd64.whl:

Publisher: release.yml on pawlenartowicz/glmm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file glmm-0.1.0-cp310-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for glmm-0.1.0-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0777b372a3f5f624cca0efa74e9acdf1a11ecd1ffc01eb81b1c8dc0bffe2411d
MD5 0a2ddb71e2448e159c7ddef97475702c
BLAKE2b-256 3c020b50dc857d4bec6c1ec80be3d664c078b3cfa418a73c5132b79907d2f243

See more details on using hashes here.

Provenance

The following attestation bundles were made for glmm-0.1.0-cp310-abi3-manylinux_2_28_x86_64.whl:

Publisher: release.yml on pawlenartowicz/glmm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file glmm-0.1.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

  • Download URL: glmm-0.1.0-cp310-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.10+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for glmm-0.1.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1079e5a750f06dea94bfe2891e5627a88ffd9803fa9495c2bc92f9a7ab8a658e
MD5 97a461753f5b8d2dec072cfc572d7f5c
BLAKE2b-256 57a6aa66ef0fd04a81130b13734f8a4a934f12fe3ca9e3daadf3f5d36cab9a6a

See more details on using hashes here.

Provenance

The following attestation bundles were made for glmm-0.1.0-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on pawlenartowicz/glmm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page