linreg_core/regularized/mod.rs
1//! Ridge and Lasso regression (glmnet-compatible implementations).
2//!
3//! This module provides regularized regression methods that are compatible with
4//! R's glmnet package. The implementations follow the same objective functions,
5//! standardization conventions, and scaling approaches as glmnet.
6//!
7//! # Objective Function
8//!
9//! The elastic net objective (which includes ridge and lasso as special cases) is:
10//!
11//! ```text
12//! minimize over (β₀, β):
13//!
14//! (1/(2n)) * Σᵢ (yᵢ - β₀ - xᵢᵀβ)²
15//! + λ * [(1 - α) * ||β||₂² / 2 + α * ||β||₁]
16//! ```
17//!
18//! Where:
19//! - `α = 0`: Ridge regression (L2 penalty)
20//! - `α = 1`: Lasso regression (L1 penalty)
21//! - `β₀` (intercept) is **never penalized**
22//! - `λ` controls the overall penalty strength
23//!
24//! # Standardization
25//!
26//! By default, predictors are standardized before fitting (matching glmnet's
27//! `standardize=TRUE` default):
28//!
29//! - Each column of X is centered to mean 0 (if intercept is used)
30//! - Each column is scaled to unit variance
31//! - Coefficients are returned on the **original scale**
32//!
33//! # Compatibility with glmnet
34//!
35//! These implementations match R's glmnet behavior:
36//!
37//! - Same objective function form
38//! - Same standardization defaults
39//! - Intercept is never penalized
40//! - Coefficients are returned on original data scale
41//!
42//! # Modules
43//!
44//! - [`preprocess`] - Data standardization utilities
45//! - [`ridge`] - Ridge regression (L2 penalty)
46//! - [`lasso`] - Lasso regression (L1 penalty)
47//! - [`path`] - Lambda path generation for regularization paths
48
49pub mod lasso;
50pub mod path;
51pub mod preprocess;
52pub mod ridge;
53
54// Re-exports for convenience
55pub use lasso::{lasso_fit, LassoFit, LassoFitOptions};
56pub use path::{make_lambda_path, LambdaPathOptions};
57pub use preprocess::{standardize_xy, unstandardize_coefficients, StandardizationInfo};
58pub use ridge::{ridge_fit, RidgeFit, RidgeFitOptions};