Deviance goodness-of-fit test (source code)

= Deviance goodness-of-fit test
{title2=$D\approx\chi^2_{n-p}$}

A <deviance goodness-of-fit test> compares a fitted <generalized linear model> with its <saturated statistical model>. With $n$ <independent> response <groups>, an identifiable rank-$p$ mean model and known common <dispersion parameter> $\phi$, the candidate statistic is the <scaled deviance>
$$
D^*=D/\phi=2\{\ell_{\rm sat}-\ell_{\rm fit}\}.
$$
In an appropriate large-information regime, compare it with a <chi-squared distribution> on $n-p$ <statistical degrees of freedom>. For a <normal linear model> this is exact when $\phi=\sigma^2$ is known: $D$ is the <residual sum of squares>. For <Poisson regression>, $\phi=1$; adequate expected cell counts are still needed for a useful approximation.<Generalized Linear Models in R by Nathaniel E. Helwig>[Section 1, Deviance and Estimating phi]{ref}

More individual <Bernoulli> observations do not automatically justify comparing their residual <deviance> with $\chi^2_{n-p}$. Small cell counts, dependence and <overdispersion> can invalidate that calibration. An unknown <dispersion parameter> also needs an explicit estimation and testing convention; estimating it from $D/(n-p)$ and then treating $D/\widehat\phi$ as an independent goodness-of-fit check is circular.