Skip to main content

Crate solow_robust

Crate solow_robust 

Source
Expand description

§solow-robust

Robust linear regression by M-estimation, matching the reference’s robust linear model (RLM).

The estimator minimizes Σ ρ((yᵢ − xᵢ·β) / σ) for a robust criterion ρ using iteratively reweighted least squares (IRLS), re-estimating the scale σ from the residuals at each step.

use ndarray::{Array1, Array2};
use solow_robust::{norms::TukeyBiweight, Rlm};

// A noisy line near y = 2 + 0.5·x with a gross outlier at the last point.
let x: Vec<f64> = (1..=10).map(|i| i as f64).collect();
let y = Array1::from(vec![
    2.6, 3.1, 3.4, 4.1, 4.4, 5.1, 5.4, 6.1, 6.4, 100.0,
]);
let exog =
    Array2::from_shape_fn((10, 2), |(i, j)| if j == 0 { 1.0 } else { x[i] });
let res = Rlm::new(y, exog, TukeyBiweight::default())
    .unwrap()
    .fit()
    .unwrap();
assert!(res.converged);
// The redescending norm fully rejects the outlier ...
assert_eq!(res.weights[9], 0.0);
// ... so the slope stays close to the clean trend rather than ~10.
assert!((res.params[1] - 0.5).abs() < 0.05);

§Components

Re-exports§

pub use norms_ext::Hampel;
pub use norms_ext::RamsayE;
pub use norms_ext::TrimmedMean;

Modules§

norms
Robust criterion functions (norms) used by M-estimation.
norms_ext
Additional robust criterion functions (norms) for M-estimation.
scale
Robust scale estimators used to standardize residuals during IRLS.

Structs§

Rlm
A robust linear model awaiting estimation.
RlmResults
The fitted result of an Rlm.

Enums§

Conv
Convergence criterion for the IRLS loop.
ScaleEst
The scale estimator used to standardize residuals between IRLS steps.