Skip to main content

regression_diagnostics/logistic/
mod.rs

1//! Diagnostics for **binary logistic regression** — a different statistical
2//! framework from OLS, not an extension of it, and provided here as its own
3//! self-contained set of types.
4//!
5//! Logistic regression models `P(y = 1) = 1/(1 + e^{−Xβ})` and is fit by maximum
6//! likelihood; there is no closed-form hat matrix and residuals are not Gaussian.
7//! So the diagnostics are the ones that are actually defined for this likelihood:
8//!
9//! * [`LogisticFit`] — the maximum-likelihood fit via **IRLS** (Fisher scoring),
10//!   with coefficient standard errors, Wald `z`-statistics and p-values.
11//! * [`deviance_residuals`] / [`pearson_residuals`] — the two standard residual
12//!   scales for a non-Gaussian GLM.
13//! * [`GoodnessOfFit`] via [`LogisticFit::goodness_of_fit`] — null/residual
14//!   deviance, McFadden's pseudo-R², AIC/BIC, and the **Hosmer–Lemeshow** test.
15//! * [`leverage`] and [`cooks_distance`] — the logistic (weighted-hat-matrix)
16//!   analogues of the OLS influence measures.
17//!
18//! # Response convention
19//!
20//! The response must be binary, coded `0.0` / `1.0`, with both classes present.
21//! As with OLS the caller owns the design matrix, including any intercept column.
22//!
23//! # Separation
24//!
25//! When the classes are perfectly (or quasi-) separable the maximum-likelihood
26//! coefficients diverge to ±∞ and no finite fit exists. IRLS then fails to
27//! converge and construction returns [`RegressionError::NotConverged`](crate::RegressionError::NotConverged)
28//! rather than reporting enormous, meaningless coefficients.
29
30mod fit;
31mod goodness;
32mod influence;
33mod residuals;
34
35pub use fit::LogisticFit;
36pub use goodness::{GoodnessOfFit, HosmerLemeshow};
37pub use influence::{cooks_distance, leverage};
38pub use residuals::{deviance_residuals, pearson_residuals};