Solution (source code)

= Solution

A standard moment estimator is the <Pearson dispersion estimator>
$$
\boxed{
\widehat\phi=
\frac1{n-p}\sum_{i=1}^n
\frac{(Y_i-\widehat\mu_i)^2}{V(\widehat\mu_i)}}.
$$
For Bernoulli data, $V(\mu)=\mu(1-\mu)$. The deviance divided by its residual degrees of freedom is a common alternative.