'Estimates the dispersion/scale.
Type of scale can be chose in the fit method.
Parameters
mu : array
mu is the mean response estimate
Returns
Estimate of scale
Notes
The default scale for Binomial and Poisson families is 1.  The default
for the other families is Pearson\'s Chi-Square estimate.
See also
statsmodels.genmod.generalized_linear_model.GLM.fit for more information'

def estimate_scale(self, mu):

    if (not self.scaletype):
        if isinstance(self.family, (families.Binomial, families.Poisson)):
            return 1.0
        else:
            resid = (self.endog - mu)
            return ((self.iweights * (np.power(resid, 2) / self.family.variance(mu))).sum() / self.df_resid)
    if isinstance(self.scaletype, float):
        return np.array(self.scaletype)
    if isinstance(self.scaletype, str):
        if (self.scaletype.lower() == 'x2'):
            resid = (self.endog - mu)
            return ((self.iweights * (np.power(resid, 2) / self.family.variance(mu))).sum() / self.df_resid)
        elif (self.scaletype.lower() == 'dev'):
            return (self.family.deviance(self.endog, mu, self.iweights) / self.df_resid)
        else:
            raise ValueError(('Scale    %s    with    type    %s    not    understood' % (self.scaletype, type(self.scaletype))))
    else:
        raise ValueError(('Scale    %s    with    type    %s    not    understood' % (self.scaletype, type(self.scaletype))))
