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 |
|
Scale |
|
|
|
|
|
|
|
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
Getting started
Theory in pictures
How-to examples
Reference
- API reference
- Porting from R’s robustbase::lmrob
- The
engine_c=Truefast path Control(rng="R")performance- Numerical notes
- FAQ / troubleshooting
- “Algorithm did not converge”
- “X’ W X is singular; consider cov=‘.vcov.w’”
- “Wald CI looks suspiciously narrow”
- Confidence vs prediction vs tolerance interval
- How do I get bit-identical fits to R?
- How do I pick
nResample? - How do I make it faster?
LmRobvslmrob?predict()is returning weird values- Why does
setting="KS2014"usepsi="lqq"by default? - See what the fitter is doing
- Where do I report bugs?