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 ndarray::Array1;

use crate::OlsFit;

/// Leverage `hᵢ` (the diagonal of the hat matrix) for each observation.
///
/// This is already computed efficiently at fit time from the thin `Q` factor —
/// the full `n × n` hat matrix is never materialized — and simply surfaced here.
///
/// # Interpretation
///
/// Leverage measures how unusual an observation's **predictor** values are,
/// independent of its response. High leverage is *potential* influence, not
/// influence itself: a high-leverage point that happens to sit on the fitted line
/// barely moves it. Combine leverage with residual size — that is exactly what
/// [`cooks_distance`](super::cooks_distance) and [`dffits`](super::dffits) do.
///
/// Each `hᵢ ∈ [0, 1]` and `Σ hᵢ = p`, so the average leverage is `p/n`; the
/// common flags are multiples of that average (`2p/n`, `3p/n`).
pub fn leverage(fit: &OlsFit) -> Array1<f64> {
    fit.leverage().to_owned()
}