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.13.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.13-cp313-cp313-win_amd64.whl (473.2 kB view details)

Uploaded CPython 3.13Windows x86-64

pylmrob-0.5.13-cp313-cp313-manylinux_2_28_x86_64.whl (552.1 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

pylmrob-0.5.13-cp313-cp313-manylinux_2_28_aarch64.whl (519.5 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

pylmrob-0.5.13-cp313-cp313-macosx_11_0_arm64.whl (330.7 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pylmrob-0.5.13-cp312-cp312-win_amd64.whl (473.7 kB view details)

Uploaded CPython 3.12Windows x86-64

pylmrob-0.5.13-cp312-cp312-manylinux_2_28_x86_64.whl (550.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

pylmrob-0.5.13-cp312-cp312-manylinux_2_28_aarch64.whl (520.1 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

pylmrob-0.5.13-cp312-cp312-macosx_11_0_arm64.whl (332.1 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pylmrob-0.5.13-cp311-cp311-win_amd64.whl (475.1 kB view details)

Uploaded CPython 3.11Windows x86-64

pylmrob-0.5.13-cp311-cp311-manylinux_2_28_x86_64.whl (553.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

pylmrob-0.5.13-cp311-cp311-manylinux_2_28_aarch64.whl (529.2 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

pylmrob-0.5.13-cp311-cp311-macosx_11_0_arm64.whl (331.3 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pylmrob-0.5.13-cp310-cp310-win_amd64.whl (475.3 kB view details)

Uploaded CPython 3.10Windows x86-64

pylmrob-0.5.13-cp310-cp310-manylinux_2_28_x86_64.whl (554.2 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

pylmrob-0.5.13-cp310-cp310-manylinux_2_28_aarch64.whl (529.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

pylmrob-0.5.13-cp310-cp310-macosx_11_0_arm64.whl (332.5 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: pylmrob-0.5.13.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.13.tar.gz
Algorithm Hash digest
SHA256 86a22028f321b508de53be196ef7ee4e22005b59902533a475f942d3a4722a78
MD5 af40161e4690d5add1e12467c29f3cb7
BLAKE2b-256 9cef8b99edc6e7c5604b6007bf20c7583ff1015ff7465b4df3722fd6ac1f6cf5

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylmrob-0.5.13.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.13-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: pylmrob-0.5.13-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 473.2 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.13-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 01d36fa63bd673a78a5490b9c05b294b6f3ada43cb77fe5e10999b0c5996c6f1
MD5 56e3bc5b709252e2653e2dd7290321e8
BLAKE2b-256 8b6a5a111607ce90d3ae517a9aa2520c9c760d2909f6099c17c226b904f029ad

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylmrob-0.5.13-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.13-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pylmrob-0.5.13-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bf7df648812edaa2251ca59b884072ff779dd76d04e59d66e85de7b63bde541e
MD5 cae7d10e08305a3ee6566f538b1aaa83
BLAKE2b-256 387efa40347e03e04dbde73019ba7e0abbdcf13143d59f9918c9b29e716e059c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylmrob-0.5.13-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.13-cp313-cp313-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pylmrob-0.5.13-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 322417288b9a98e4ec4b1744499d3ffddeb6b195a18b7bc1909c05ca20946394
MD5 f8b893e89bd4a18913e15c0200ab75ea
BLAKE2b-256 948014dd0cce001d9b220b41049ebe14c8cffe4280d6e0e525c032833bf498e4

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylmrob-0.5.13-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.13-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pylmrob-0.5.13-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2a87034f3bf6f0cf9d9ec802c2373aec7e1a6b59b862930f3d30c1284f3d0665
MD5 12b07a91801b45ca60b3c2988d97c9d2
BLAKE2b-256 64091827bebe3ca3893eda81616c7fb7dfba449e48e8ad2611a624c78fbab185

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylmrob-0.5.13-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.13-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pylmrob-0.5.13-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 473.7 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.13-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 d30320c461a99cf98d991331fdc86dac3d6acb5eeb5d7963b31057bc3feab0a1
MD5 119a34b5964e49bfe703a22548431664
BLAKE2b-256 ae7ff621e094fc840479001bdcff3a44d714e0a5a7e5a64f05710af70410d9e1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylmrob-0.5.13-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.13-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pylmrob-0.5.13-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b8f0aad748d9bcae9cc1842e2ab822c369823f822def294d499c5b59875b7982
MD5 4b815afdec2ed92471c6a16996ff4049
BLAKE2b-256 17da0348d0c60def2131277278b2bea6f52ce576af4a3827f70a5dc2a58a7ef0

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylmrob-0.5.13-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.13-cp312-cp312-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pylmrob-0.5.13-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 4b64ce23f6fb2a7c6ffe5ec83df98d34908105970bcee0031f860d8f44101710
MD5 916945bacddfc5092d2fe33f6f9a9284
BLAKE2b-256 54ddaaed360ac33dd02f420d65d4f97ae2d7923cd3353e7d1306b92f359934a6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylmrob-0.5.13-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.13-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pylmrob-0.5.13-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e3426577e5226f6c7cc36aa1df53cbc670b1ce5c930ff3ee35d58df66d8450f7
MD5 ce592d8ec0a5a3fcc9fe45229eae2e1f
BLAKE2b-256 78cea566e8ef01dd1f2136701f2b5d63323d4c16c006802a2ccb0981410ebf72

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylmrob-0.5.13-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.13-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: pylmrob-0.5.13-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 475.1 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.13-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 6656c0393ab95c950d30028391277e063881ba6a316960872404e3894159eb21
MD5 8bdbde83c6213b8cf629cf3ef4dbf453
BLAKE2b-256 9945dd7e6514c1b28914c36764ba4288e71f0bd032a9617be82c217ace47072f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylmrob-0.5.13-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.13-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pylmrob-0.5.13-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 22444af5e4d524cb765a2e682c626ce9b15970afa61b6b860e46fe4e8153a1e2
MD5 412fca78883afe5f198107f03385439c
BLAKE2b-256 9ebda598eaa5da457ea48b5999a05f54688c35e71d66f240407a09eea8200bd5

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylmrob-0.5.13-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.13-cp311-cp311-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pylmrob-0.5.13-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 b5b2171da142268dcc74bc0a2853af9ccfd6d65f8c00272bd2183f8c2d996751
MD5 fcef29745f54c9779c2fb92d72bcfa90
BLAKE2b-256 7689e4f8c167067759f8214056d84b1bc5377b41528f431cd6f95bd6035663a5

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylmrob-0.5.13-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.13-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pylmrob-0.5.13-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8e436b134be34f1f846743db49f33ec8b6f495431049e4d2fc4ba7ef4397d8ad
MD5 bbd7850d97cc6168f4f5fddb242cc7eb
BLAKE2b-256 9bbe88258249ead0a0d2de8f92d80dbf4d16033681dc3d913f850d30a5cfe43b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylmrob-0.5.13-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.13-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: pylmrob-0.5.13-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 475.3 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.13-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 cda856156bfb24f49032d62fe5612d2923c8c03c5e27f0eb0d45a621e1b1bf72
MD5 fca351e3cd289cf1ec4aa93ec51b6391
BLAKE2b-256 9cecec9ebe8604033845ee7ed732323b4f7459c03c13de258b7acab6bfde2859

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylmrob-0.5.13-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.13-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pylmrob-0.5.13-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5df4b9daff57b0692a14bd6d06c758759ddb45d4670637c76e5d1e07041c966f
MD5 93bc6ad22cd62a221f9cff72e43edfd1
BLAKE2b-256 d6b50606333271dd49a506fa16cae0c4d507b7c9a3c7493f1e6dbade1e560abb

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylmrob-0.5.13-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.13-cp310-cp310-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pylmrob-0.5.13-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 7d22d8e30599e649af28aa2c1bea6444ea5be0fa1d8f34b9be53dc2ee1c04015
MD5 d9c52cb42809ed8d7256f688dd839907
BLAKE2b-256 e3921f54cd73c8f9e85b163cbc52b88cbfe1cb229d18c45c2f7c54a87dee6657

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylmrob-0.5.13-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.13-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pylmrob-0.5.13-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d0c58b618d00f5bf90f7a3afe51d20ec8da0f739beae546944c6f2e883ea822d
MD5 22287a2a01368058f9f63770ac97c796
BLAKE2b-256 f3ac454e4c30b4553076f54c9967aca3ad54a9eb1c5abe1905f729ee876e03ea

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylmrob-0.5.13-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