pylmrob

Note

Parts of this documentation, including the theory write-up and the notebooks under “Theory in pictures”, were drafted with help from Claude Opus 4.7. Verify claims against the source code or the cited papers before relying on them.

Python port of R’s robustbase::lmrob MM-estimator for robust linear regression. Same algorithm, same numbers (to rtol=1e-3 on the classical datasets), Cython-accelerated, and roughly as fast as R itself.

pip install pylmrob
from pylmrob import lmrob

fit = lmrob("stack.loss ~ Air.Flow + Water.Temp + Acid.Conc.", df, seed=42)
print(fit.summary())

Why robust regression

OLS gets pulled toward outliers. A few bad rows in y (or in X) can move your slope by an order of magnitude. MM-estimators downweight those rows automatically and still recover ~95% of OLS efficiency on clean data. The canonical reference is robustbase::lmrob; pylmrob is that algorithm, unchanged where it matters, in Python.

Quick numbers

Output

Agreement with R

Coefficients

rtol=1e-3 (rtol=1e-6 on most rows)

Scale

rtol=1e-3

vcov.avar1, vcov.w

rtol=1e-3 element-wise

summary() t/p values

rtol=2e-3

anova() chi-sq, p

rtol=2e-3

For sub-1e-5 reproducibility against R’s exact RNG stream, opt in with Control(rng="R"). See rng-r-perf and Numerical notes for the details.

Median wall-clock on the bench corpus: 0.93× R. Status: alpha; the public API is stable enough to depend on but may change.

Contents

Indices