# Hosmer–Lemeshow test

${\displaystyle H=\sum _{g=1}^{G}{\frac {(O_{1g}-E_{1g})^{2}}{E_{1g}}}+{\frac {(O_{0g}-E_{0g})^{2}}{E_{0g}}}=\sum _{g=1}^{G}{\frac {(O_{1g}-E_{1g})^{2}}{N_{g}\pi _{g}}}+{\frac {(N_{g}-O_{1g}-(N_{g}-E_{1g}))^{2}}{N_{g}(1-\pi _{g})}}=\sum _{g=1}^{G}{\frac {(O_{1g}-E_{1g})^{2}}{N_{g}\pi _{g}(1-\pi _{g})}}.\,\!}$
Here O1g, E1g, O0g, E0g, Ng, and πg denote the observed Y=1 events, expected Y=1 events, observed Y=0 events, expected Y=0 events, total observations, predicted risk for the gth risk decile group, and G is the number of groups. The test statistic asymptotically follows a ${\displaystyle \chi ^{2}}$ distribution with G − 2 degrees of freedom. The number of risk groups may be adjusted depending on how many fitted risks are determined by the model. This helps to avoid singular decile groups.