robustmodels¶
Robust statistics for Python: estimators of location, scale, covariance and linear, rank-based and nonlinear regression, exact rank tests, generalized linear models, principal components, discriminant analysis, robust clustering, statistical depth and outlier detectors, that stay reliable when part of the data are outliers, with multivariate kernel density estimation and shape-constrained estimators.
pip install robustmodels
Requires Python 3.10+, NumPy, SciPy, scikit-learn and Matplotlib.
Quick start¶
One gross outlier ruins the mean and the standard deviation, but not their robust counterparts:
>>> import numpy as np
>>> from robustmodels import location, scale
>>> x = [1, 2, 2, 3, 4, 100]
>>> round(float(np.mean(x)), 2), round(float(np.std(x, ddof=1)), 2)
(18.67, 39.86)
>>> location.hodges_lehmann(x), round(scale.qn(x), 2)
(3.0, 1.36)
The covariance estimators are scikit-learn estimators:
>>> from robustmodels.covariance import MCD
>>> X = np.random.default_rng(0).normal(size=(100, 2))
>>> X[:10] += 10 # ten outliers
>>> mcd = MCD(random_state=0).fit(X)
>>> mcd.location_.round(2).tolist()
[0.01, 0.1]
>>> mcd.covariance_.round(2).tolist()
[[0.93, 0.15], [0.15, 1.06]]
Contents¶
Page |
What it covers |
|---|---|
Hodges-Lehmann, M-estimators, tau location, trimmed and winsorized means |
|
MAD, Qn, Sn, Pn, tau scale, M-scale, medcouple and tail weights |
|
Scientific sources, formulas and R conventions |
|
MCD, MRCD, MVE, OGK, Stahel-Donoho, Peña-Prieto (KSD), S- and MM-estimators; outlier detection |
|
Robust PCA (ROBPCA, projection pursuit), LDA and QDA, Hotelling’s T² and MANOVA |
|
TCLUST and trimmed k-means |
|
Kernel density estimation with a full bandwidth matrix, density derivatives, highest density regions and two-sample tests |
|
Log-concave density estimation and regression by antitonic score matching |
|
MM, S, LTS and nonlinear M regression |
|
Rank regression (Wilcoxon R-estimator) and exact Wilcoxon tests with ties |
|
Robust logistic and Poisson models, inference and numerical conventions |
|
Halfspace depth (exact in any dimension) and regression depth, Tukey median and bagplot |
|
Stahel-Donoho, adjusted and directional outlyingness; projection depth |
|
Regression and PCA outlier maps, quantile plots, distance-distance plots, tolerance ellipses, scree plots, biplots, classification regions, adjusted boxplots, bagplots, outlyingness, highest density regions, log-concave densities, antitonic scores, coefficient comparisons, depth-depth plots and trimmed likelihood curves |
|
Stars, Hawkins–Bradu–Kass, wood gravity, stack loss and hemophilia: the documented outliers found, with summaries and diagnostic plots |
|
Definitions, pre-release checks and documented differences from R |
Each page explains how to choose and use the estimators, then documents every function and class: definition, parameters, return value, references and an example.
Conventions¶
Univariate functions take a one-dimensional sample of finite values and return a Python
float.NaNor infinite values raiseValueError.An empty sample returns
nan; a single observation has zero scale.Covariance estimators take a matrix with observations in rows and variables in columns.
Invalid parameters raise
ValueErrorwith the name of the parameter.The breakdown point is the largest fraction of arbitrary outliers an estimator tolerates. The Gaussian efficiency compares its variance with that of the classical estimator on clean normal data.