anofox-regression
A robust statistics library for regression analysis in Rust, validated against R (VALIDATION).
This library provides sklearn-style regression estimators with full statistical inference support including standard errors, t-statistics, p-values, confidence intervals, and prediction intervals.
Features
-
Linear Regression
- Ordinary Least Squares (OLS) with full inference
- Weighted Least Squares (WLS)
- Ridge Regression (L2 regularization)
- Elastic Net (L1 + L2 regularization via L-BFGS)
- Recursive Least Squares (RLS) with online learning
- Bounded Least Squares (BLS/NNLS) with box constraints
- Dynamic Linear Model (LmDynamic) with time-varying coefficients
-
Generalized Linear Models
- Poisson GLM (Log, Identity, Sqrt links) with offset support
- Negative Binomial GLM (overdispersed count data with theta estimation)
- Binomial GLM (Logistic, Probit, Complementary log-log)
- Tweedie GLM (Gaussian, Poisson, Gamma, Inverse-Gaussian, Compound Poisson-Gamma)
-
Augmented Linear Model (ALM)
- 24 distributions: Normal, Laplace, Student-t, Gamma, Beta, Log-Normal, and more
- Based on the greybox R package
-
Quantile & Monotonic Regression
- Quantile Regression (IRLS with asymmetric weights, any τ ∈ (0,1))
- Isotonic Regression (PAVA algorithm for monotonic constraints)
-
Smoothing & Classification
- LOWESS (Locally Weighted Scatterplot Smoothing)
- AID (Automatic Identification of Demand) classifier
-
Loss Functions
- MAE, MSE, RMSE, MAPE, sMAPE, MASE, pinball loss
-
Model Diagnostics
- R², Adjusted R², RMSE, F-statistic, AIC, AICc, BIC
- Leverage, Cook's distance, VIF, studentized residuals
Installation
Add to your Cargo.toml:
[]
= "0.5"
Examples
The library includes runnable examples demonstrating each major feature:
Quick Start
OLS Regression
use *;
use ;
let x = from_fn;
let y = from_fn;
let fitted = builder
.with_intercept
.build
.fit?;
println!;
println!;
Prediction Intervals
let result = fitted.predict_with_interval;
println!;
println!;
println!;
Poisson GLM
let fitted = log
.with_intercept
.build
.fit?;
println!;
let counts = fitted.predict_count;
Logistic Regression
let fitted = logistic
.with_intercept
.build
.fit?;
let probs = fitted.predict_probability;
Augmented Linear Model
// Laplace regression (robust to outliers)
let fitted = builder
.distribution
.with_intercept
.build
.fit?;
println!;
Quantile Regression
// Median regression (tau = 0.5)
let fitted = builder
.tau
.build
.fit?;
println!;
// 90th percentile regression
let fitted_90 = builder
.tau
.build
.fit?;
Isotonic Regression
// Fit monotonically increasing function
let fitted = builder
.increasing
.build
.fit_1d?;
println!;
let predictions = fitted.predict_1d;
Validation
This library is developed using Test-Driven Development (TDD) with R as the oracle (ground truth). All implementations are validated against R's statistical functions:
| Rust | R Equivalent | Package |
|---|---|---|
OlsRegressor |
lm() |
stats |
WlsRegressor |
lm() with weights |
stats |
RidgeRegressor, ElasticNetRegressor |
glmnet() |
glmnet |
BlsRegressor |
nnls() |
nnls |
PoissonRegressor |
glm(..., family=poisson) |
stats |
BinomialRegressor |
glm(..., family=binomial) |
stats |
NegativeBinomialRegressor |
glm.nb() |
MASS |
TweedieRegressor |
tweedie() |
statmod |
AlmRegressor |
alm() |
greybox |
QuantileRegressor |
rq() |
quantreg |
IsotonicRegressor |
isoreg() |
stats |
| Diagnostics | cooks.distance(), hatvalues(), vif() |
stats, car |
All 485+ test cases ensure numerical agreement with R within appropriate tolerances.
For complete transparency on the validation process, see validation/VALIDATION.md, which documents tolerance rationale for each method and reproduction instructions.
Dependencies
- faer - High-performance linear algebra
- statrs - Statistical distributions
- argmin - Numerical optimization (L-BFGS)
Attribution
This library includes Rust implementations of algorithms from several open-source projects. See THIRD_PARTY_NOTICES for complete attribution and license information.
Key attributions:
- greybox - ALM distributions and AID classifier methodology (independent implementation)
- argmin (MIT/Apache-2.0) - L-BFGS optimization
- faer (MIT) - Linear algebra operations
- statrs (MIT) - Statistical distributions
License
MIT License