regression_diagnostics/regularized/mod.rs
1//! Diagnostics for **regularized** linear regression — the family the OLS
2//! diagnostics deliberately excluded, now provided as first-class types.
3//!
4//! Regularization changes the fit in ways the OLS formulas can't be reused for.
5//! Under ridge the hat matrix becomes `H_λ = X(XᵀX + λI)⁻¹Xᵀ`, so leverage,
6//! degrees of freedom, and everything built on them differ; lasso has no
7//! closed-form hat matrix at all. Each estimator therefore gets its own fitted
8//! type with the diagnostics that are actually well-defined for it:
9//!
10//! * [`RidgeFit`] — closed-form ridge (via SVD), with **effective degrees of
11//! freedom** `Σ dⱼ²/(dⱼ²+λ)`, ridge leverage, GCV, effective AIC/BIC, and a
12//! [`ridge_vif`](RidgeFit::ridge_vif) that generalizes the OLS VIF and reduces
13//! to it at `λ = 0` — the "VIF before/after regularization" comparison.
14//! * [`LassoFit`] — coordinate-descent lasso, whose natural degrees-of-freedom
15//! estimate is simply the size of the **active set** (Zou–Hastie–Tibshirani).
16//!
17//! ## Penalty conventions (read before comparing `λ` across estimators)
18//!
19//! * **Ridge** penalizes the centered predictors on their given scale; the
20//! intercept (a detected constant column) is never penalized. Ridge is *not*
21//! scale-invariant, so standardizing predictors first is the usual practice.
22//! * **Lasso** standardizes predictors internally and minimizes
23//! `(1/2n)‖y − Xβ‖² + λ‖β‖₁`, so its `λ` is on a different scale than ridge's.
24//!
25//! Neither is a drop-in for the other's `λ`; they are documented per-type.
26
27mod lasso;
28mod ridge;
29
30pub use lasso::LassoFit;
31pub use ridge::{select_lambda_gcv, RidgeFit};