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

Uploaded CPython 3.13Windows x86-64

pylmrob-0.5.15-cp313-cp313-manylinux_2_28_x86_64.whl (557.5 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

pylmrob-0.5.15-cp313-cp313-manylinux_2_28_aarch64.whl (525.0 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

pylmrob-0.5.15-cp313-cp313-macosx_11_0_arm64.whl (336.1 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pylmrob-0.5.15-cp312-cp312-win_amd64.whl (479.2 kB view details)

Uploaded CPython 3.12Windows x86-64

pylmrob-0.5.15-cp312-cp312-manylinux_2_28_x86_64.whl (555.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

pylmrob-0.5.15-cp312-cp312-manylinux_2_28_aarch64.whl (525.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

pylmrob-0.5.15-cp312-cp312-macosx_11_0_arm64.whl (337.5 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pylmrob-0.5.15-cp311-cp311-win_amd64.whl (480.6 kB view details)

Uploaded CPython 3.11Windows x86-64

pylmrob-0.5.15-cp311-cp311-manylinux_2_28_x86_64.whl (559.4 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

pylmrob-0.5.15-cp311-cp311-manylinux_2_28_aarch64.whl (534.6 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

pylmrob-0.5.15-cp311-cp311-macosx_11_0_arm64.whl (336.8 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pylmrob-0.5.15-cp310-cp310-win_amd64.whl (480.7 kB view details)

Uploaded CPython 3.10Windows x86-64

pylmrob-0.5.15-cp310-cp310-manylinux_2_28_x86_64.whl (559.6 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

pylmrob-0.5.15-cp310-cp310-manylinux_2_28_aarch64.whl (534.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

pylmrob-0.5.15-cp310-cp310-macosx_11_0_arm64.whl (338.0 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: pylmrob-0.5.15.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.15.tar.gz
Algorithm Hash digest
SHA256 41ffa33f924387f82b82443dac049dcb5cbfd587837c8137e3070cd669cb6406
MD5 adc8bf732be00c4171e096d9ff7caab0
BLAKE2b-256 3d02dc1bf964cb3d8f9cab98837ad010bb590300ea5df3541629126bce6147d0

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pylmrob-0.5.15-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 478.7 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.15-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 3370f79ca28ce8cc49f990beaabf8dc43dd75748e91de7573f19ac1f4b784c62
MD5 2f7d54c9bc5415c8d86da2e0ad724c18
BLAKE2b-256 79fc35c01a2547827695e00e0c2345da0d41099bbb7620ff283f51b0f1561147

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pylmrob-0.5.15-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8adb6ee13d29172d1732ee57675e5216177d343d143ede2a83aaa393f0b03e3b
MD5 a98945e7097ed07a6a053a5708c913e1
BLAKE2b-256 08f97c3832f9e278042775ad70e38d58a73a202e9d7788e5a78cdab2c676ff39

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pylmrob-0.5.15-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 c7345e564ef2a0b7e59a1fd0cf76adde239b58ac442ac59cc3107f2d1f4f16fe
MD5 de1a3bf29d884169ac853e526a554a4b
BLAKE2b-256 80de142c1b00abde46baccf3babf97cbda3b56e2b56c40fc296cc60af5b8b2af

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pylmrob-0.5.15-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0cec6bd45207e39c72f5729f38d14215cea2de13b6e67738d71b6d1b09923d87
MD5 553e1013f10ce5bb5c2ae4a087a74a73
BLAKE2b-256 947a2c0a6941fe54502a3cc5400e6ce7ac367906e1bc708328aecb6181e15d7e

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pylmrob-0.5.15-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 479.2 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.15-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 3f04935b7f6a958229ddc1fe983f563c123a7c1b2cf20144d582fd853a907df6
MD5 c222b7ea28df70a75b0727b0928d8d46
BLAKE2b-256 4475f2baa4bef0ac1e5bc815d6dbf8c03f22d7f53f698163e983f8bd4382554b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pylmrob-0.5.15-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 728e492c26649d9abbc2f22cf50c1adcc6808f45f191199597f193122e4cf66b
MD5 0397af04cc31c55d367e5a0307786ed9
BLAKE2b-256 220c4e6ca038e1109daecb7647bdace0d690818b7e5ff82e45e0c83e86b2de38

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pylmrob-0.5.15-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 d368e9519d4764c298737efeafb36b1f3bc92f7e022b98f259cad0c916c3c0fe
MD5 092d19eadbb5411bbc7a277e67931d93
BLAKE2b-256 14f280de619d4905d3d3ed6291f58d9896e06025480e9a69656c7324e2c4dcc3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pylmrob-0.5.15-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 15e92a849f16d21a89bcf5196417f941ffbdc1ae6ebd833fa2f592451a5861fe
MD5 65c2b119b1e4f1214876a1d4aec3eb4b
BLAKE2b-256 583b0d44ba98557712a6592767721cf2cb69d9b9ac60fb58f39bacbb42de25d3

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pylmrob-0.5.15-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 480.6 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.15-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 7869a6729152cbbdd3eb563869c8ae3dfd6b6916aa3d194104b0cdcd36187dfd
MD5 694665773f21e12925d1e9586a4d9b1f
BLAKE2b-256 25f6ddc0b45195b38d035a132160c72af12b0bf59825f1db9a8f901cc9e84f07

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pylmrob-0.5.15-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4658252326076eb091f11c220aa56aa0bf559704c80e78a01c9e3a3eac7f0514
MD5 3fe0ee3768c7a076e8e9e13e922f782e
BLAKE2b-256 92e7442efd360fe100633fde587cae8f3e1273f048e077d70e001d60ae7615b9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pylmrob-0.5.15-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 a0290f3048ea891605119ab2152194b796cd37bc9b5deb15c535a41ee41d37bd
MD5 cefe9db379bb0af1499d2a700de0a1ff
BLAKE2b-256 9778ea3346b54a754a335f51503bded4bf3db5c3e03e21a1779e5d5736e9f099

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pylmrob-0.5.15-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 454c68cc0b5e1178d11cae24b00774252491a5e9844a604ae8b2c9281e6253ad
MD5 bf2744671ff9ecc501278469869c02cd
BLAKE2b-256 ac2cdd62daf131e010dfc7273498e5b3e666e741f588570acadfecbd4afe5708

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pylmrob-0.5.15-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 480.7 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.15-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 9a44d00b61f8b4da67a9d49caaa73dc459157e6085f4df17e030be4461af04dd
MD5 02712900e552b46b250f2eac54e4457d
BLAKE2b-256 15be2349d4e086a91eb44b23e5eaee9d07039b79243d5b03c104aa8ee52f4886

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pylmrob-0.5.15-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 731ff5d54592213911b36a64ce919fe1999dc7b528fdad70d05c682b6544394d
MD5 10865313b71a412dcf4365c7ef2445b8
BLAKE2b-256 1d2929a63c18ab24d9d3cfb9726830b0ae7151e5b545cb1e5e94e9e177c86a64

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pylmrob-0.5.15-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 dfd939e1fb91046bc8c8dbc3ed075a9bb827ed4f909a4e8058bda839b25ed129
MD5 969eb2c533efe42ebe0b8341df45149e
BLAKE2b-256 8912e16061f1535e4c925ff69975d5e6cdb7a4043fa0bd63be3e7c16f79e9178

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pylmrob-0.5.15-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cda40db8d7714cb7dc1f50018b5906e48a1393427c8bb354ec830591053030f6
MD5 d2a3e6f26f658113c2915946708ff3bd
BLAKE2b-256 25474064232cff5047d35bed5815068b9a1e01d3901d92b1e8b0f463bae1db6a

See more details on using hashes here.

Provenance

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