The HPLOGISTIC Procedure

The Hosmer-Lemeshow Goodness-of-Fit Test

To evaluate the fit of the model, Hosmer and Lemeshow (2000) proposed a statistic that they show, through simulation, is distributed as chi-square when there is no replication in any of the subpopulations. This goodness-of-fit test is available only for binary response models.

The unit interval is partitioned into 2,000 equal-sized bins, and each observation $i$ is placed into the bin that contains its estimated event probability. This effectively sorts the observations in increasing order of their estimated event probability.

The observations (and frequencies) are further combined into $G$ groups. By default $G$=10, but you can specify $G\ge 5$ with the NGROUPS= suboption of the LACKFIT option in the MODEL statement. Let $F$ be the total frequency. The target frequency for each group is $T=\lfloor F/G+0.5\rfloor $, which is the integer part of $F/G+0.5$. Load the first group ($g_ j, j=1$) with the first of the 2,000 bins that has nonzero frequency $f_1$, and let the next nonzero bin have a frequency of $f$. PROC HPLOGISTIC performs the following steps for each nonzero bin to create the groups:

  1. If $j=G$, then add this bin to group $g_ j$.

  2. Otherwise, if $f_ j< T$ and $f_ j+\lfloor f/2\rfloor \le T$, then add this bin to group $g_ j$.

  3. Otherwise, start loading the next group ($g_{j+1}$) with $f_{j+1}=f$, and set $j=j+1$.

If the final group $g_ j$ has frequency $f_ j < T/2$, then add these observations to the preceding group. The total number of groups actually created, $g$, can be less than $G$.

The Hosmer-Lemeshow goodness-of-fit statistic is obtained by calculating the Pearson chi-square statistic from the $2\times g$ table of observed and expected frequencies. The statistic is written

\[  \chi ^2_{\mathit{HL}} = \sum _{j=1}^ g \frac{(O_ j - F_ j \bar{\pi }_ j)^2}{F_ j \bar{\pi }_ j (1 - \bar{\pi }_ j)}  \]

where, for the $j$th group $g_ j$, $F_ j=\sum _{i\in g_ j} f_ i$ is the total frequency of subjects, $O_ j$ is the total frequency of event outcomes, and $\bar{\pi }_ j=\sum _{i\in g_ j} f_ i\widehat{p_ i}/F_ j$ is the average estimated predicted probability of an event outcome. Let $\epsilon $ be the square root of the machine epsilon divided by 4,000, which is about 2.5E–12. Any $\bar{\pi }_ j<\epsilon $ is set to $\epsilon $; similarly, any $\bar{\pi }_ j>1-\epsilon $ is set to $1-\epsilon $.

The Hosmer-Lemeshow statistic is compared to a chi-square distribution with $g-r$ degrees of freedom. You can specify $r$ with the DFREDUCE= suboption of the LACKFIT option in the MODEL statement. By default, $r=2$, and to compute the Hosmer-Lemeshow statistic you must have $g-r\ge 1$. Large values of $\chi ^2_{\mathit{HL}}$ (and small p-values) indicate a lack of fit of the model.