gamrs
Generalised additive models in Rust, with a Python API. gamrs reimplements R's mgcv: the same bases, penalties and REML criterion, tested against mgcv's own output.
pip install gamrs
Wheels for Linux, macOS and Windows, Python 3.9 and later.
Example
import numpy as np
import pandas as pd
from gamrs import Gam, CrTerm, TeTerm, ReTerm
rng = np.random.default_rng(0)
n = 2_000
df = pd.DataFrame({
"x": rng.uniform(0, 10, n),
"u": rng.uniform(0, 1, n),
"v": rng.uniform(0, 1, n),
"g": rng.integers(0, 50, n),
})
y = np.sin(df.x) + df.u * df.v + rng.normal(0, 0.3, 50)[df.g] + rng.normal(0, 0.3, n)
# y ~ s(x, bs = "cr") + te(u, v) + s(g, bs = "re")
gam = Gam(
terms=[CrTerm("x", k=10), TeTerm(cols=("u", "v"), k=(5, 5)), ReTerm("g")],
method="REML",
).fit(df, y)
gam.predict(df)
mu, lo, hi = gam.predict_ci(df, level=0.95)
gam.edf_, gam.lambda_, gam.reml_value_
More in docs/quickstart.md.
What it fits
| gamrs | mgcv |
|---|---|
CrTerm("x", k=10) |
s(x, bs = "cr") |
TpsTerm(cols=("x", "z")) |
s(x, z, bs = "tp") |
TeTerm(cols=("x", "z")), TiTerm(cols=...) |
te(x, z), ti(...), any number of margins |
ReTerm("g") |
s(g, bs = "re") |
ScTerm("x", "increasing"), TeScTerm(...) |
s(x, bs = "sc"), te(..., bs = "sc") as fitted by scasm() |
ParametricTerm("x") |
a linear term |
by= on CrTerm, TeTerm, ReTerm |
s(x, by = w) |
Families: gaussian, binomial, poisson, quasipoisson, quasibinomial,
Gamma, inverse_gaussian, nb, tw, scat, ocat. Also quantile
regression in the style of qgam (fit_quantile) and the location–scale
families gaulss (fit_gaulss) and shash (fit_shash).
Fitted models expose predict, predict_ci, coef_, vcov_, edf_,
lambda_ and fit_stats_, and serialise for inference-only use with
GamPredictor.
Agreement with mgcv
Every family and term type has parity tests against fixtures generated by
mgcv 1.9-4 (scripts/r/, tests/). Two deliberate
differences:
method="fREML"selects mgcv's Fellner–Schall smoothing-parameter updates (GLM families; others fall back to Newton with a warning), but always on the REML criterion. Results matchgam(method = "REML"), notbam(method = "fREML").- Monotone (
sc) terms choose their smoothing parameters by the REML thatscasm()reports, not the reduced criterion it iterates on. That criterion jumps where a constraint starts or stops binding, soscasm()can stop without converging. At the same smoothing parameters gamrs andscasm()agree to about 1e-12.
Speed
A random effect plus four smooths, one thread, Intel i7-8565U, mgcv 1.9-4. Seconds per fit.
| Model | mgcv gam |
mgcv bam |
gamrs 0.17 |
|---|---|---|---|
| Gaussian, n = 20,000, 100 levels | 15.8 | 0.49 | 0.08 |
| Gaussian, n = 2,000, 1,000 levels | 63.5 | 6.85 | 1.12 |
| Gaussian, n = 20,000, 1,000 levels | — | 15.1 | 2.03 |
| Poisson, n = 20,000, 50 levels | 6.59 | 1.22 | 0.81 |
| Poisson, n = 20,000, 1,000 levels | — | 102 | 4.21 |
| Scaled t, n = 20,000, 50 levels | 10.8 | 1.86 | 1.51 |
| Scaled t, n = 20,000, 1,000 levels | — | 239 | 9.67 |
— not run. gamrs's fitted values are within 4e-4 standard deviations of
gam's. bam(discrete = TRUE) is faster on the 50-level models, but its
fitted values are 0.5–1.6% of a standard deviation away from gam's.
Fits release the GIL, so independent fits run in parallel on Python threads.
Set OPENBLAS_NUM_THREADS=1 when running several at once.
Rust
The core is a Rust crate. Bases, families, the inner penalised fit and the
REML outer search are separate layers (src/basis, src/family,
src/inner, src/score, src/fit), and the Python package is a thin PyO3
layer over them.
License
MIT. Release notes are in the changelog.
Metadata
Release files for gamrs 0.17.2
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 |
|---|---|---|---|---|
| gamrs-0.17.2.tar.gz | 7.4 MB | Without provenance | Details for gamrs-0.17.2.tar.gz |
Built distributions (wheels)
Total release size: 151.8 MB
Release files / gamrs-0.17.2.tar.gz
| Download URL | gamrs-0.17.2.tar.gz |
|---|---|
| Size | 7.4 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1f0370eb725ce59a4142dee6791eba69cf4ec82857a4daccea80a668a95370c5
|
|
BLAKE2b-256 checksum How to use checksums |
a593657e3f47278431367e66cd8bac49dab3a97dc1c48f48063c242b22cf9794
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.16.0
|
Release files / gamrs-0.17.2-pp311-pypy311_pp73-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | gamrs-0.17.2-pp311-pypy311_pp73-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 6.9 MB |
| Tags | Linux glibc 2.17+ x86-64 PyPy 3.11 PyPy 3.11 7.3 |
|
SHA-256 checksum How to use checksums |
ccfe6661ce9d67a15bbd37dbe0352abae73c85fad6c5a7cd41d693834aa30509
|
|
BLAKE2b-256 checksum How to use checksums |
b101c73c8032228d3628d9d020568f9c53fc92b214228cf5a56aebcc88e608f9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.16.0
|
Release files / gamrs-0.17.2-cp315-cp315-win_amd64.whl
| Download URL | gamrs-0.17.2-cp315-cp315-win_amd64.whl |
|---|---|
| Size | 4.3 MB |
| Tags | CPython 3.15 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
561539888468ea058e4b758ad585d57b49cf32e64b543acee9aa6ad35d5c1e77
|
|
BLAKE2b-256 checksum How to use checksums |
4f6164046ff1c71fe3088860f151f1c8077368e9ad8e75f116f033828b26eb6c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.16.0
|
Release files / gamrs-0.17.2-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | gamrs-0.17.2-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 6.9 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
5a4b19bd52825f88cfbdb39ebef9b1be528b5b389ec1542ea3e2cea258f26b8a
|
|
BLAKE2b-256 checksum How to use checksums |
1c4d8ead3e1a7f96ea839982b8bef579f7e384198e1467fbdc1c70d508792594
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.16.0
|
Release files / gamrs-0.17.2-cp314-cp314-win_amd64.whl
| Download URL | gamrs-0.17.2-cp314-cp314-win_amd64.whl |
|---|---|
| Size | 4.3 MB |
| Tags | CPython 3.14 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
9e9c35cd8ea829e3eea7e7803d32256b4fff848590cef13be6fa8d7fb4189af8
|
|
BLAKE2b-256 checksum How to use checksums |
60d4336829f06df8bdcc3b11f9d7e54660b2cdf2c1e0d692a40af74e491f4e7e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.16.0
|
Release files / gamrs-0.17.2-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | gamrs-0.17.2-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 6.9 MB |
| Tags | CPython 3.14 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
53a2d4dba315c0801a03d6e4158957a12507cd1ae9c4a96116cfb2966ebfd756
|
|
BLAKE2b-256 checksum How to use checksums |
8f4513c91c191ffd05fb5e7b804fa8cd5be264f9c3c6adf47ab16853d665ca60
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.16.0
|
Release files / gamrs-0.17.2-cp314-cp314-macosx_11_0_arm64.whl
| Download URL | gamrs-0.17.2-cp314-cp314-macosx_11_0_arm64.whl |
|---|---|
| Size | 5.7 MB |
| Tags | CPython 3.14 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
b98bd4172077e367430de84cda083815008d51037cc29d86def862337ed331ee
|
|
BLAKE2b-256 checksum How to use checksums |
00848e1af9aea665a8f6fa98c1e9baa046498b892b77de6acf66d06cae074182
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.16.0
|
Release files / gamrs-0.17.2-cp314-cp314-macosx_10_13_x86_64.whl
| Download URL | gamrs-0.17.2-cp314-cp314-macosx_10_13_x86_64.whl |
|---|---|
| Size | 7.4 MB |
| Tags | CPython 3.14 macOS 10.13+ x86-64 |
|
SHA-256 checksum How to use checksums |
561e85b7c6b617aa69fd15969baddc49df2a82dbed4f67847eac6f235364f82e
|
|
BLAKE2b-256 checksum How to use checksums |
5ae7a458c0daaf9fbbec61c1fe9f356378a44ab83637b6c2a38c4bc7beb228e7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.16.0
|
Release files / gamrs-0.17.2-cp313-cp313-win_amd64.whl
| Download URL | gamrs-0.17.2-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 4.3 MB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
1a4ac27d8dd1fdc8374983d0b176a2ad415e5b4c0a098bce6c934d4f788284df
|
|
BLAKE2b-256 checksum How to use checksums |
10b3836d5dcc5bac14576897c0331957115bc4242e0d17749b8241137e16443e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.16.0
|
Release files / gamrs-0.17.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | gamrs-0.17.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 6.9 MB |
| Tags | CPython 3.13 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
8a5b12750ff322f67ae2915ca95195ee46ba62f75d00e5f070d90e3a2c638d1b
|
|
BLAKE2b-256 checksum How to use checksums |
6d4500e6c2d874d161f63c66ed04429971de0907b5b14c652b669389f4003a90
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.16.0
|
Release files / gamrs-0.17.2-cp313-cp313-macosx_11_0_arm64.whl
| Download URL | gamrs-0.17.2-cp313-cp313-macosx_11_0_arm64.whl |
|---|---|
| Size | 5.7 MB |
| Tags | CPython 3.13 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
45c36c82614a369fb94d9162ce6e73fc35bc2a0a1a05d7a35571a154b85e0fa3
|
|
BLAKE2b-256 checksum How to use checksums |
27dd79b542f13aac5b96aef7ea42179687e169ea16efe688d349649862face76
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.16.0
|
Release files / gamrs-0.17.2-cp313-cp313-macosx_10_13_x86_64.whl
| Download URL | gamrs-0.17.2-cp313-cp313-macosx_10_13_x86_64.whl |
|---|---|
| Size | 7.4 MB |
| Tags | CPython 3.13 macOS 10.13+ x86-64 |
|
SHA-256 checksum How to use checksums |
56ffee20fb752d717c7c67b0ead899c9ba26e73858bb343b500d7b6da927e15e
|
|
BLAKE2b-256 checksum How to use checksums |
c209a01dcd1d7767b7ce08ce80d789bed75215c7100771e4619b43678da19c63
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.16.0
|
Release files / gamrs-0.17.2-cp312-cp312-win_amd64.whl
| Download URL | gamrs-0.17.2-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 4.3 MB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
655feed387c645f1d3107024e89f9413076b8dd0fd7ff7ec574a00499cf45ded
|
|
BLAKE2b-256 checksum How to use checksums |
ac26f1d5247185db8adc3760d7f430795f5622d458e3d0b168ee741d8144c3ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.16.0
|
Release files / gamrs-0.17.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | gamrs-0.17.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 6.9 MB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
7ca2e9224a11edf08e1c7f06fae295cc2f718397dedf31c743f36afef8fb8ced
|
|
BLAKE2b-256 checksum How to use checksums |
e7a2333ad358f1adcdb9dd7406ef6a216ed0697bd5e4a943d030668c730fcbee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.16.0
|
Release files / gamrs-0.17.2-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | gamrs-0.17.2-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 5.7 MB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
32e49adf9cc223b907f1dfa4b3e288eaa332862862981167b8e5f747b0619614
|
|
BLAKE2b-256 checksum How to use checksums |
647521d0b2227b5027187da941ab3b2e6c77a2f1000c40c0f5c63801f43839a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.16.0
|
Release files / gamrs-0.17.2-cp312-cp312-macosx_10_13_x86_64.whl
| Download URL | gamrs-0.17.2-cp312-cp312-macosx_10_13_x86_64.whl |
|---|---|
| Size | 7.4 MB |
| Tags | CPython 3.12 macOS 10.13+ x86-64 |
|
SHA-256 checksum How to use checksums |
06695997312012af653b61bb38140e28cf0148ff41bb373a7997e9774c530609
|
|
BLAKE2b-256 checksum How to use checksums |
cb64fc72fd0cf30a19c9b7d33b651573f30487d1a0e4c9e8d0141a18b0980e94
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.16.0
|
Release files / gamrs-0.17.2-cp311-cp311-win_amd64.whl
| Download URL | gamrs-0.17.2-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 4.3 MB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
2f3a228f36d977c96bf4d178ec553be94f8b8c740194be395174f3a7dd184aab
|
|
BLAKE2b-256 checksum How to use checksums |
d5fae07afd8244e40099fab0c9f8eec50121a4cbf58e3267ead8e06b05851b1a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.16.0
|
Release files / gamrs-0.17.2-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | gamrs-0.17.2-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 6.9 MB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
6311c82e8ac4676c138d2249c71264ab89b31218255e28de72a7b4979fcb3747
|
|
BLAKE2b-256 checksum How to use checksums |
1b46c65d886b151dff53eed0a645ce26d416732473118ee58d9b8d291c7fa6a2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.16.0
|
Release files / gamrs-0.17.2-cp311-cp311-macosx_11_0_arm64.whl
| Download URL | gamrs-0.17.2-cp311-cp311-macosx_11_0_arm64.whl |
|---|---|
| Size | 5.7 MB |
| Tags | CPython 3.11 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
02b421e26cfe06d95d3ac0b7c0959409ad436a8722fc1f43bc666193523f9cbc
|
|
BLAKE2b-256 checksum How to use checksums |
9e3df9480ad97b6e44f80a91a6a8ede50d5f8869b55815287f9ec4aa7d68cb5a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.16.0
|
Release files / gamrs-0.17.2-cp311-cp311-macosx_10_13_x86_64.whl
| Download URL | gamrs-0.17.2-cp311-cp311-macosx_10_13_x86_64.whl |
|---|---|
| Size | 7.4 MB |
| Tags | CPython 3.11 macOS 10.13+ x86-64 |
|
SHA-256 checksum How to use checksums |
c0dfb8a3d0396a22743f1efa653ae97c7f973bf7c118415c66131af31f7699c3
|
|
BLAKE2b-256 checksum How to use checksums |
1a5dfb01cdcb1c1a3b9650acaef0830f7e2a8936c3ca003535a129da17d07df9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.16.0
|
Release files / gamrs-0.17.2-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | gamrs-0.17.2-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 6.9 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
d25dda4bf6be275b54c154608054f843435aba1b5fe1054061f1e904b6de696f
|
|
BLAKE2b-256 checksum How to use checksums |
3bebded2272e5d2773b339507a843082c14803fdefc2558379b2f9c4a05bf19e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.16.0
|
Release files / gamrs-0.17.2-cp310-cp310-macosx_10_13_x86_64.whl
| Download URL | gamrs-0.17.2-cp310-cp310-macosx_10_13_x86_64.whl |
|---|---|
| Size | 7.4 MB |
| Tags | CPython 3.10 macOS 10.13+ x86-64 |
|
SHA-256 checksum How to use checksums |
4b611d9e8c5692dfad0d9274c57679697a3fee3c0f7a574a78a7a102d22bbcfa
|
|
BLAKE2b-256 checksum How to use checksums |
1a37e8d2146f641e6f1ca3d0aff25a89ac6731415a26fc988bf59f570d4ddd37
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.16.0
|
Release files / gamrs-0.17.2-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | gamrs-0.17.2-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 6.9 MB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
6e7ef0a0165ca2c5736c0b4fdceb044e4a9ed0d5f8de75cde2ca3cc23ea57bd0
|
|
BLAKE2b-256 checksum How to use checksums |
f340e0d2ee172fe6156b9e99b209c45c0f15a7a4a597a02cba8eaf8f1c704623
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.16.0
|
Release files / gamrs-0.17.2-cp39-cp39-macosx_10_13_x86_64.whl
| Download URL | gamrs-0.17.2-cp39-cp39-macosx_10_13_x86_64.whl |
|---|---|
| Size | 7.5 MB |
| Tags | CPython 3.9 macOS 10.13+ x86-64 |
|
SHA-256 checksum How to use checksums |
a3725e662c0f51968f26db98ba5ca9c07e788743184dc1f071405267e070a49b
|
|
BLAKE2b-256 checksum How to use checksums |
ed151baeaefda78a002e797ba29f8cd3a3fe170b69603418eba3395075c55d04
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.16.0
|
Security for gamrs 0.17.2
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.