Expand description
Diagnostics for binary logistic regression — a different statistical framework from OLS, not an extension of it, and provided here as its own self-contained set of types.
Logistic regression models P(y = 1) = 1/(1 + e^{−Xβ}) and is fit by maximum
likelihood; there is no closed-form hat matrix and residuals are not Gaussian.
So the diagnostics are the ones that are actually defined for this likelihood:
LogisticFit— the maximum-likelihood fit via IRLS (Fisher scoring), with coefficient standard errors, Waldz-statistics and p-values.deviance_residuals/pearson_residuals— the two standard residual scales for a non-Gaussian GLM.GoodnessOfFitviaLogisticFit::goodness_of_fit— null/residual deviance, McFadden’s pseudo-R², AIC/BIC, and the Hosmer–Lemeshow test.leverageandcooks_distance— the logistic (weighted-hat-matrix) analogues of the OLS influence measures.
§Response convention
The response must be binary, coded 0.0 / 1.0, with both classes present.
As with OLS the caller owns the design matrix, including any intercept column.
§Separation
When the classes are perfectly (or quasi-) separable the maximum-likelihood
coefficients diverge to ±∞ and no finite fit exists. IRLS then fails to
converge and construction returns RegressionError::NotConverged
rather than reporting enormous, meaningless coefficients.
Structs§
- Goodness
OfFit - Bundle of overall logistic goodness-of-fit statistics.
- Hosmer
Lemeshow - Result of the Hosmer–Lemeshow goodness-of-fit test.
- Logistic
Fit - A fitted binary logistic-regression model.
Functions§
- cooks_
distance - Cook’s-distance analogue for logistic regression (Pregibon):
- deviance_
residuals - Deviance residuals
sign(yᵢ − pᵢ)·√(−2[yᵢ ln pᵢ + (1 − yᵢ) ln(1 − pᵢ)]). - leverage
- Logistic leverage — the diagonal of the weighted hat matrix
H = W^{1/2}X(XᵀWX)⁻¹XᵀW^{1/2}, i.e.hᵢ = wᵢ · xᵢᵀ(XᵀWX)⁻¹xᵢwithwᵢ = pᵢ(1 − pᵢ). - pearson_
residuals - Pearson residuals
(yᵢ − pᵢ) / √(pᵢ(1 − pᵢ)).