Skip to main content

Robust statistics for Python: M/S/MM regression, robust scale and MCD/OGK/Tyler covariance; Rust-powered bindings to robust-rs.

Project description

robustat-py

Robust statistics for Python: Rust-powered bindings to robust-rs. M/S/MM regression, robust scale, robust multivariate location–scatter (MCD, OGK, Tyler) and the influence-function sampling theory, all with a numpy interface.

The numerics run in compiled Rust (via PyO3 and rust-numpy); randomized estimators (S/MM/LTS/MCD) are reproducible by default and expose a seed.

Install

pip install robustat-py

From source (this repo)

Requires a Rust toolchain and maturin:

pip install maturin
maturin develop -m py/Cargo.toml --features extension-module   # into the active venv
# or build a wheel:
maturin build  -m py/Cargo.toml --release

Quick start

import numpy as np
import robustat_py as rp

# --- Robust regression -------------------------------------------------------
# starsCYG: four giant stars flip the OLS slope negative; MM recovers the
# physical positive slope and rejects them (R's lmrob default).
x_raw, y = rp.datasets.stars_cyg()
X = np.column_stack([np.ones(len(y)), x_raw[:, 0]])   # prepend an intercept

mm = rp.MMEstimator(seed=1).fit(X, y)     # 50% breakdown AND ~95% efficiency
mm.coefficients                           # -> np.ndarray; slope > 0
mm.gaussian_efficiency()                  # ~0.95
mm.breakdown_point                        # 0.5

# Outliers only in y? A plain M-estimator is cheaper (but 0 breakdown vs leverage):
fit = rp.MEstimator(rp.Huber(), rp.Mad()).fit(X, y)
fit.weights                               # near 0 for down-weighted rows

# --- Robust covariance / multivariate outliers -------------------------------
Xs, _ = rp.datasets.stackloss()
mcd = rp.Mcd(seed=1).fit(Xs)              # FAST-MCD, affine equivariant
mcd.outliers(0.975)                       # bool per row, χ² cutoff
mcd.location, mcd.scatter

# --- Robust location & scale -------------------------------------------------
data = [2.1, 2.3, 1.9, 2.0, 2.2, 47.0]    # one gross outlier
rp.m_location(data).estimate              # ~2.16, not the mean (~9.58)
rp.Mad().scale(data)
rp.hodges_lehmann(data).estimate

API at a glance

Estimators (build, then .fit)

Class .fit returns Notes
MEstimator(loss, scale) RegressionFit IRLS; fast/convex; 0 breakdown vs leverage
SEstimator(loss, seed=…) RegressionFit FAST-S; 50% breakdown
MMEstimator(seed=…) RegressionFit start here; 50% breakdown + ~95% efficiency
Lts(seed=…) LtsFit FAST-LTS; coverage knob
Mcd(seed=…) McdFit start here for covariance; RMCD by default
Ogk(scale) ScatterFit deterministic, positive-definite
MScatter(loss) ScatterFit monotone M-scatter (low breakdown)
Tyler() TylerFit distribution-free shape (unit det)

Functions: m_location, trimmed_mean, winsorized_mean, hodges_lehmann, theil_sen, mahalanobis_distances, classical_covariance, distance_cutoff, outlier_flags, gaussian_efficiency, asymptotic_variance, breakdown_point.

Losses (redescending ones marked *): Huber(k=1.345), Tukey(c=4.685) *, Cauchy *, Welsch *, Andrews *, Hampel(a,b,c) *, LeastSquares, L1. Each exposes rho/psi/weight/psi_prime, tuning, is_redescending, rho_sup and gaussian_efficiency()/asymptotic_variance()/influence().

Scales: Mad(), Qn(), Sn(), HuberProposal2(). Every loss/scale argument also accepts a name string ("huber", "tukey", "mad", "qn", …).

Datasets: robustat_py.datasets.stackloss(), robustat_py.datasets.stars_cyg() (each returns (X, y) with predictors only; prepend your own intercept column).

Errors surface as robustat_py.RobustError (a ValueError subclass).

License

MIT OR Apache-2.0, matching robust-rs.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

robustat_py-0.1.0-cp39-abi3-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.9+Windows x86-64

robustat_py-0.1.0-cp39-abi3-musllinux_1_2_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ x86-64

robustat_py-0.1.0-cp39-abi3-musllinux_1_2_aarch64.whl (1.2 MB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ ARM64

robustat_py-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

robustat_py-0.1.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (986.6 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

robustat_py-0.1.0-cp39-abi3-macosx_11_0_arm64.whl (848.4 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

robustat_py-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file robustat_py-0.1.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: robustat_py-0.1.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for robustat_py-0.1.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 9f517ee14e483f82d2d21dedc21e295fb1cc406b199a9278dbc45bcafa417256
MD5 8ed5c52351539999536617a9316d0860
BLAKE2b-256 7eaba30f22c17e76dfca93f19e318ffee009ad6d6f70ad76ec8cebbcc400932b

See more details on using hashes here.

Provenance

The following attestation bundles were made for robustat_py-0.1.0-cp39-abi3-win_amd64.whl:

Publisher: release.yml on coes300/robust-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file robustat_py-0.1.0-cp39-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for robustat_py-0.1.0-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 4a5e2062eab7ff729fc4f7995480629552036032ee8c984807544bac24dfab68
MD5 607a8388fb94b23a94e5b032435269af
BLAKE2b-256 1a2367b1229f7109ada9c82e7fae56aea8ed0d367ece803f54eca20414c47c55

See more details on using hashes here.

Provenance

The following attestation bundles were made for robustat_py-0.1.0-cp39-abi3-musllinux_1_2_x86_64.whl:

Publisher: release.yml on coes300/robust-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file robustat_py-0.1.0-cp39-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for robustat_py-0.1.0-cp39-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 d803241357f76235593f82b3623c105822bc5cf407f97a594012ad0ebb124d16
MD5 833725a2862efe5784763c42ea452b8b
BLAKE2b-256 0abca1890a5b265bea4e1971a5a99c5923acd789015423179fa83ac93367a5f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for robustat_py-0.1.0-cp39-abi3-musllinux_1_2_aarch64.whl:

Publisher: release.yml on coes300/robust-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file robustat_py-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for robustat_py-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f9284b08b30e297e9d6e56220476ca39fc559f0704def2e9831bf9fbd8ce7b74
MD5 c15ae617baf3d5e33c3def6aad140369
BLAKE2b-256 8d9057e969853a9567ac0faa0224c850cde4a871f98ecc6dd2803ee2db3ef8b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for robustat_py-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on coes300/robust-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file robustat_py-0.1.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for robustat_py-0.1.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c1a8b697f5cda4e860031611064104963f0a0a37d0782fd730c0bb8e5566f3c6
MD5 1c6c20540397203577e2903a555e238b
BLAKE2b-256 845f78b8b9c5c55b6d2242d4266648e6bee6665b0498d9c5a2485f54b7321d19

See more details on using hashes here.

Provenance

The following attestation bundles were made for robustat_py-0.1.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on coes300/robust-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file robustat_py-0.1.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for robustat_py-0.1.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a738423b9d914df3b4b93fa8bdc4d8b289206eefe523fe7063a48c59c9b78082
MD5 547bb019394fdc15befc0928a147aa92
BLAKE2b-256 344701f5f10322526f8f3872ff5152fb5028be1d9114fc9747d88c5845a8a9c3

See more details on using hashes here.

Provenance

The following attestation bundles were made for robustat_py-0.1.0-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on coes300/robust-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file robustat_py-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for robustat_py-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 d69349ed85a60456473b0869437881eeb828818f6d93548e7a8d10806d319c4b
MD5 e827d8b8b1cdfe43a37b02333053b4fc
BLAKE2b-256 0be0ae0e3ae513ae5088b247730180405cef1a1efd66cce760d07f01bd434bd5

See more details on using hashes here.

Provenance

The following attestation bundles were made for robustat_py-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yml on coes300/robust-rs

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