Hosmer-Lemeshow Test
Hosmer-Lemeshow Test
Overview
Definition
The Hosmer-Lemeshow Test is a statistical test for goodness of fit for logistic regression models. It assesses whether the observed event rates match expected event rates in subgroups of the model population.
1. Procedure
- Predict Probabilities: Calculate predicted probabilities for all observations.
- Group Data: Sort observations by predicted probability and divide them into
groups (typically deciles, ). - Compare: In each group, calculate the expected number of events versus observed events.
- Chi-Square Statistic:
Where is observed events, is expected events, and is the average predicted probability in group .
2. Hypothesis
: The model fits the data well (No significant difference between observed and predicted). : The model does not fit the data well.
Interpretation:
- p > 0.05: Evidence of good fit (Fail to reject
). - p < 0.05: Evidence of poor fit (Reject
).
Limitation
The test is sensitive to grouping method and sample size. It is often recommended to use it alongside calibration plots.
3. Python Implementation
Note: Not available in standard sklearn. Custom implementation or libraries like scikit-learn-extra or statistical packages are needed.
# Conceptual implementation
# Group data by deciles of predicted probability
# Calculate Chi-square between observed and expected counts
4. Related Concepts
- Binary Logistic Regression - The model being tested.
- ROC & AUC - Measures discrimination (distinguishing classes) rather than calibration (accuracy of probability).
- Confusion Matrix - Classification performance.