Skip to main content

Python port of robustbase::lmrob (MM regression)

Project description

pylmrob

CI Docs License: GPL-3.0-or-later

Python port of the lmrob MM-estimator from R's robustbase package.

Documentation: pylmrob.readthedocs.io.

Status: v0.5.11 (alpha). End-to-end pipeline matches R's lmrob element-wise on the classical robust regression datasets (stackloss, coleman, delivery, aircraft, phosphor, etc.) within rtol=1e-3 for both coefficients and covariance. Median wall-clock is 0.93x R across the 34-case bench corpus. See plan.md for the full roadmap and docs/numerical-notes.md for known divergences from R.

What works

  • All six psi families (bisquare, huber, hampel, optimal, lqq, ggw) match R's Mpsi/Mchi/Mwgt to rtol=1e-12 (1e-7 for ggw rho's polynomial approximation).
  • M-scale matches R's find_scale to rtol=1e-9.
  • Fast-S resampling + MM iteration produces final coefficients matching R on the validation corpus (10 classical datasets) within per-dataset tolerances ranging 1e-3 (well-conditioned) to 1e-1 (small-n).
  • Sandwich covariance estimator (vcov_avar1).
  • Control presets matching R's lmrob.control(setting={"KS2014","KS2011","MM"}).
  • Affine equivariance, scale equivariance, regression equivariance verified via Hypothesis property tests.
  • init="M-S" for factor designs (Maronna-Yohai 2000, 4-phase port of robustbase's R_lmrob_M_S).
  • D-scale refinement (Koller & Stahel 2014) for setting="KS2014" and setting="KS2011"; full SMDM pipeline matches R element-wise.
  • vcov.w with all five cov.corrfact branches plus the Huber finite-sample correction, matching R within rtol=1e-3.
  • summary() (coefficient table, robust R-squared) and anova() (Wald + Deviance) matching R element-wise.
  • Per-case weights argument: matches R element-wise on the NumPy path. Non-trivial weights force Control(engine_c=False) for now.
  • Default Control() runs the monolithic Cython engine (single nogil C block for fast-S, MM, D-scale, and vcov); see Performance.

What does not work yet

  • Bit-identical reproducibility with R's MT RNG. We use NumPy's PCG64 (waived in plan.md §5.2; coefficients agree with R within basin-of-attraction tolerances documented in docs/numerical-notes.md).

Performance

Median wall-clock vs R across the 34-case bench corpus is 0.93x; pylmrob is faster than R on more than half of cases (down to 0.32x R on n>=2000 fits) and within 1-2x R on small classical datasets.

The default Control() runs the fit through a monolithic Cython engine (fast-S, MM, D-scale, and vcov in one nogil C block). At larger n (n*p^2 >= 100k) lmrob() auto-falls-back to a threaded NumPy path because the monolithic kernel is a single non-parallel call. To force the legacy NumPy path explicitly, pass Control(engine_c=False).

See docs/bench-report.md for the full per-case table and docs/engine_c.md for the trade-off discussion.

Install (from source)

Requires Python 3.10+, a C compiler, and (for the validation harness) a local R install with robustbase.

git clone https://github.com/anevolbap/pylmrob
cd pylmrob
uv venv
uv pip install --no-build-isolation -e ".[dev]"
pytest

Quickstart

import pandas as pd
from pylmrob import lmrob, Control

df = pd.read_csv("stackloss.csv")
fit = lmrob(
    "stack.loss ~ Air.Flow + Water.Temp + Acid.Conc.",
    df,
    control=Control(setting="KS2014"),
    seed=42,
)
print(fit.summary())

# Coefficients match R within rtol=1e-3:
# (Intercept) -41.5246
# Air.Flow      0.9388
# Water.Temp    0.5796
# Acid.Conc.   -0.1129
# scale = 1.9123

# Predict on new rows; the formula spec is re-applied automatically.
new_rows = pd.DataFrame({
    "Air.Flow":    [60, 80],
    "Water.Temp":  [20, 25],
    "Acid.Conc.":  [85, 90],
})
fit.predict(new_rows)

# Confidence intervals:
fit.confint(level=0.95)

Documentation

The Sphinx docs are hosted at pylmrob.readthedocs.io and built on every push (config in .readthedocs.yaml). To build locally:

uv pip install -e ".[docs]" --no-build-isolation
cd docs && uv run sphinx-build -b html -W . _build/html
open _build/html/index.html

Pages: quickstart, API reference, R-to-Python porting cheatsheet, and the numerical-notes log of documented divergences from R.

Comparison with statsmodels

statsmodels.robust.RLM implements M-estimators (Huber, Tukey, Hampel) but not MM-estimators. It will not give you the high-breakdown-point + high-efficiency combo that lmrob provides. If you need MM, use pylmrob. If you only need M with no contamination concerns, RLM is fine and has a more mature API.

License

GPL-3.0-or-later, matching robustbase. See LICENSE and NOTICE.

Citing

If you use pylmrob in research, please cite the project alongside robustbase. Citation metadata is in CITATION.cff (GitHub shows a "Cite this repository" button on the sidebar). The references include the key papers: Yohai (1987) on MM-estimators, Salibian-Barrera & Yohai (2006) on the fast-S algorithm, and Koller & Stahel (2011) on the small-sample Wald correction implemented in vcov.w.

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

pylmrob-0.5.14.tar.gz (11.3 MB view details)

Uploaded Source

Built Distributions

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

pylmrob-0.5.14-cp313-cp313-win_amd64.whl (475.5 kB view details)

Uploaded CPython 3.13Windows x86-64

pylmrob-0.5.14-cp313-cp313-manylinux_2_28_x86_64.whl (554.4 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

pylmrob-0.5.14-cp313-cp313-manylinux_2_28_aarch64.whl (521.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

pylmrob-0.5.14-cp313-cp313-macosx_11_0_arm64.whl (333.0 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pylmrob-0.5.14-cp312-cp312-win_amd64.whl (476.0 kB view details)

Uploaded CPython 3.12Windows x86-64

pylmrob-0.5.14-cp312-cp312-manylinux_2_28_x86_64.whl (552.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

pylmrob-0.5.14-cp312-cp312-manylinux_2_28_aarch64.whl (522.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

pylmrob-0.5.14-cp312-cp312-macosx_11_0_arm64.whl (334.4 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pylmrob-0.5.14-cp311-cp311-win_amd64.whl (477.5 kB view details)

Uploaded CPython 3.11Windows x86-64

pylmrob-0.5.14-cp311-cp311-manylinux_2_28_x86_64.whl (556.2 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

pylmrob-0.5.14-cp311-cp311-manylinux_2_28_aarch64.whl (531.5 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

pylmrob-0.5.14-cp311-cp311-macosx_11_0_arm64.whl (333.6 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pylmrob-0.5.14-cp310-cp310-win_amd64.whl (477.6 kB view details)

Uploaded CPython 3.10Windows x86-64

pylmrob-0.5.14-cp310-cp310-manylinux_2_28_x86_64.whl (556.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

pylmrob-0.5.14-cp310-cp310-manylinux_2_28_aarch64.whl (531.4 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

pylmrob-0.5.14-cp310-cp310-macosx_11_0_arm64.whl (334.8 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file pylmrob-0.5.14.tar.gz.

File metadata

  • Download URL: pylmrob-0.5.14.tar.gz
  • Upload date:
  • Size: 11.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pylmrob-0.5.14.tar.gz
Algorithm Hash digest
SHA256 319bcc0f986fd68b7373f96f1e093f444150a5688173a40a6c951db6085e25bb
MD5 62e044f4333217154e36e2e9895d09c8
BLAKE2b-256 c368e0f4ab21a4751a90978bed6b8d3514f1cf41e0aac851e5979560393fa6f7

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylmrob-0.5.14.tar.gz:

Publisher: wheels.yml on anevolbap/pyrobustlm

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

File details

Details for the file pylmrob-0.5.14-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: pylmrob-0.5.14-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 475.5 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pylmrob-0.5.14-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 b60e25780038f74d916489c75afad80d38a9b9fdad13f74d3129882241c73945
MD5 c2a1a6fd3d0aa01c43112114012bbdae
BLAKE2b-256 c449f9c296d58c83dce9dd34ba99879971bd3f7f6ccd0fb92371874f40057cc4

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylmrob-0.5.14-cp313-cp313-win_amd64.whl:

Publisher: wheels.yml on anevolbap/pyrobustlm

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

File details

Details for the file pylmrob-0.5.14-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pylmrob-0.5.14-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f488115afc8ea75b270a29d1a63e7187557c7fd2653be0411a59fb09c71585ff
MD5 3b3ff8d7ba1261be8727002dd74ec9c1
BLAKE2b-256 88b1d896414887ed4ed296426588551f2a695de9b6c7435e234314193840c327

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylmrob-0.5.14-cp313-cp313-manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on anevolbap/pyrobustlm

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

File details

Details for the file pylmrob-0.5.14-cp313-cp313-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pylmrob-0.5.14-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 e80c33214ea4953afa4dae2c6707c01d1764a6885173f50379389d3ac10744d6
MD5 982c2b2c6b8329554c44f8ecc8692201
BLAKE2b-256 54079aef584b1069f1c6cfa178850da770aa442297af9a0ecdaa6a2edd0f70ee

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylmrob-0.5.14-cp313-cp313-manylinux_2_28_aarch64.whl:

Publisher: wheels.yml on anevolbap/pyrobustlm

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

File details

Details for the file pylmrob-0.5.14-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pylmrob-0.5.14-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 154c9ce4b276ba34febff5503ac0a85f801c015991940e9314a7c7b309efb54b
MD5 c5924f55319e21f9fc3731c8c2948289
BLAKE2b-256 2029bd1a056167d264109ea48bd79c022e732aabd123fd2eafa150387bd95b7e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylmrob-0.5.14-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: wheels.yml on anevolbap/pyrobustlm

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

File details

Details for the file pylmrob-0.5.14-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pylmrob-0.5.14-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 476.0 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pylmrob-0.5.14-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 b148514e520466b682411721b260ce36961537770eedbbebec8e955239e0dae0
MD5 3f7a3fa028a1a4d38769065a2e675227
BLAKE2b-256 c1b00f62c373d354fb5c17de30f1cc92dd572c42e984d85d14a6a6b50d9297e8

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylmrob-0.5.14-cp312-cp312-win_amd64.whl:

Publisher: wheels.yml on anevolbap/pyrobustlm

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

File details

Details for the file pylmrob-0.5.14-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pylmrob-0.5.14-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8b7c118f493d79a4e5f6b05ea145d9fc15348d4f380bd3e99e44200456bb4c48
MD5 2c762ecab09b1bf663a69a2995b6d6f9
BLAKE2b-256 e1473a4b89464aeabc2d1566e7526594c60871c7a840b9c7c09b2c0ebc31459a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylmrob-0.5.14-cp312-cp312-manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on anevolbap/pyrobustlm

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

File details

Details for the file pylmrob-0.5.14-cp312-cp312-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pylmrob-0.5.14-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 26c3c86fe71a0b375192a102523cdd64c88b84dd233bb82d7694a6bbaa23341d
MD5 2cd8c5e7cc66ccbd5abbfb73216fb55b
BLAKE2b-256 85c90b01c5d8aa74eae5d3275a3957b01a5467c8d96724f87872b8cff6f83d70

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylmrob-0.5.14-cp312-cp312-manylinux_2_28_aarch64.whl:

Publisher: wheels.yml on anevolbap/pyrobustlm

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

File details

Details for the file pylmrob-0.5.14-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pylmrob-0.5.14-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 863743f59d8ca15492a33d7e3ed863a38e6cae49ce97d4e11fa049d0531be8c3
MD5 6d07e7e3aed20d39ccbdc1649b59a269
BLAKE2b-256 febcd761481cae2d604b9f02c4af8450967967067aad49924d6c26cfbb78d22b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylmrob-0.5.14-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: wheels.yml on anevolbap/pyrobustlm

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

File details

Details for the file pylmrob-0.5.14-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: pylmrob-0.5.14-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 477.5 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pylmrob-0.5.14-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 4036b25e3c62847f50dae23b166be0b727d32c6f2716a911bfe80d610565dda8
MD5 cf167c8a8c2269112f4e93430ae5bfe1
BLAKE2b-256 c8bcb124b7b604ed749212e55050817b687189dca26c5242eb8d04cdcc362e42

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylmrob-0.5.14-cp311-cp311-win_amd64.whl:

Publisher: wheels.yml on anevolbap/pyrobustlm

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

File details

Details for the file pylmrob-0.5.14-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pylmrob-0.5.14-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cf1f8ff1c15363f4a1215a0ef9f91e8c8454d68de78aff0a67e7431c467ab592
MD5 4f970d89168cbe3ba8abcc43c482d21e
BLAKE2b-256 239406af3ad02150e8ac1a5919d9b2c4e79920a75ba5ad8a8a580f5a9a27bdda

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylmrob-0.5.14-cp311-cp311-manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on anevolbap/pyrobustlm

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

File details

Details for the file pylmrob-0.5.14-cp311-cp311-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pylmrob-0.5.14-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 6c2194b59a1713a2c32d07c8448901030010b32716fc4d5bb02bb4729395b519
MD5 0dc2ec31f0ad9bd2a626acce169d23e3
BLAKE2b-256 9fa3656590dfa9f3617bfa3bd3a168a7303d50f8fcb427e7469bafddf0fc7585

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylmrob-0.5.14-cp311-cp311-manylinux_2_28_aarch64.whl:

Publisher: wheels.yml on anevolbap/pyrobustlm

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

File details

Details for the file pylmrob-0.5.14-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pylmrob-0.5.14-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b66d5ce05af66e8144d57becdb47066246bda628de4330aa27d686a8d53baa6e
MD5 f80d4038a93330708dc299a7aa827c1c
BLAKE2b-256 75ff36c66c0eb1b5606c2f595016ba96e21e229226d79ebf4223713bf08b64b0

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylmrob-0.5.14-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: wheels.yml on anevolbap/pyrobustlm

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

File details

Details for the file pylmrob-0.5.14-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: pylmrob-0.5.14-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 477.6 kB
  • 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 pylmrob-0.5.14-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 45a105a75440a751102f00bc561a66820b68ac7b70087465660e2a6c1aa242ed
MD5 c425d215ded3b75bf1cf34844a5aca1a
BLAKE2b-256 de84599d35d0477ac2346e0c9736bb3e3ff2769f4c318bedfef37a91eaea7455

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylmrob-0.5.14-cp310-cp310-win_amd64.whl:

Publisher: wheels.yml on anevolbap/pyrobustlm

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

File details

Details for the file pylmrob-0.5.14-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pylmrob-0.5.14-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 78240565defb2e4fdf1d80840690bb69dcf23c5ff41b3d9eff3475f835c92cf7
MD5 5d922bc1180dca908aa1c2c7e58afd27
BLAKE2b-256 e6627a7d26ae772e029ab15e2ecbeb1437b0620896a45a714ecfb5e3dfd9bddc

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylmrob-0.5.14-cp310-cp310-manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on anevolbap/pyrobustlm

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

File details

Details for the file pylmrob-0.5.14-cp310-cp310-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pylmrob-0.5.14-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 217615ed136539e1c1a43177073c18e9511a37d64f1ba743b8db6297d2fc6d06
MD5 470f305dbec45157b8233a7554d931a6
BLAKE2b-256 ceaebf6f21c93ecf74fdd59a7f2c831fa8ebf812334ebe9d2c3bcce645537c1f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylmrob-0.5.14-cp310-cp310-manylinux_2_28_aarch64.whl:

Publisher: wheels.yml on anevolbap/pyrobustlm

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

File details

Details for the file pylmrob-0.5.14-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pylmrob-0.5.14-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a8037da3b077f5da701080424a1caea1b6464a0d955eca9206646a59ff66e83d
MD5 263e48626cc4dfab15d57dc0898d7dff
BLAKE2b-256 1089082c6c4cc809357e23e6d8b958b13b09e5c824f2279fe1b5793233d88114

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylmrob-0.5.14-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: wheels.yml on anevolbap/pyrobustlm

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