Goodness of fit in a GLM with scaled deviance On this page, I am interested in the section “goodness of fit”, which is near the bottom of the page and contains the table of deviance functions. 
The author states that the scaled deviance, i.e. $D^*= \frac{D(y, \mu)}{\phi} $ has a limiting $ \chi^2_{n -p} $ distribution, where $ n $ is the number of observation and $ p $ is the number of predicted parameters. 
He then goes on to say that in the case $ \phi $ is unknown, it can be predicted as $ \hat{\phi} = \frac{D}{n - p} $. If this is the case, wouldn't the scaled deviance be equal to $ \frac{D(y, \mu)}{\frac{D}{n - p}} = n - p $? I think I am misunderstanding the discrepancy between $ D(y, \mu) $ and $ D $ (without arguments).
A similar thing occurs with the scaled Pearson's chi-squared statistic.
Could someone elaborate on how to calculate scaled deviance in the case that $ \phi $ is unknown and how to proceed with the g.o.f. test?
 A: I think when you allow for unknown dispersion, the GLM is no longer a maximum likelihood technique, but maximizes a "quasi" likelihood. Because of that, the deviance is fixed by using the sample dispersion as the model dispersion (as a consequence of maximizing quasi likelihood). By treating the dispersion as a parameter in a quasilikelihood, the family of e.g. quasibinomial likelihoods are equivalent to the binomial likelihood up to a proportional constant. Maximizing quasilikelihood treats this constant like a nuisance parameter.
Think of it like this: when the probability model for the underlying GLM is correct then the sample deviance will have an expected value of 1 (as confirmed by your formulation and limiting distribution statement above). But random variation in that data will show that the probability model does not always perfectly fit such data.
When the sample deviance is egregiously different from such, this is indication that the working probability model is not a good probability framework for the observed data. This doesn't mean that the inference on parameters is incorrect. In fact, by using scaled deviance, you can account for this over or under dispersion in the working GLM and get correct inference on the parameters. This is the GLM obtained from maximum quasilikelihood. 
I recommend looking at Alan Agresti's example of horseshoe crabs and quasipoisson and quasibinomial models in Categorical Data Analysis 2nd ed for further clarification.
