regression-diagnostics 0.2.0

Statistical diagnostics for OLS regression in Rust: VIF, condition number, adjusted R2, F/AIC/BIC, residual tests (Durbin-Watson, Breusch-Pagan, White, Jarque-Bera), influence measures (leverage, Cook's distance, DFFITS), QQ-plot data, and an R/statsmodels-style summary().
Documentation
use crate::OlsFit;

/// Condition number of the design matrix: the ratio of its largest to smallest
/// singular value.
///
/// This is a single whole-design measure of ill-conditioning, complementary to
/// (and sometimes in disagreement with) the per-predictor [`vif`](super::vif).
///
/// The value is computed on the design matrix **exactly as fitted** — including
/// the intercept column and on the original (unscaled) predictor columns. Other
/// tools sometimes report the condition number of a column-scaled or normalized
/// design, which can differ substantially; the scaling convention is stated here
/// so the number is reproducible rather than ambiguous.
///
/// Returns [`f64::INFINITY`] if the smallest singular value is zero (an exactly
/// rank-deficient design — though such a design would already have failed at
/// [`OlsFit`] construction).
pub fn condition_number(fit: &OlsFit) -> f64 {
    let sv = fit.singular_values();
    match (sv.first(), sv.last()) {
        (Some(&max), Some(&min)) if min > 0.0 => max / min,
        _ => f64::INFINITY,
    }
}