'Binomial deviance residuals
Parameters
endog : array-like
Endogenous response variable
mu : array-like
Fitted mean response variable
scale : float, optional
An optional argument to divide the residuals by sqrt(scale).
The default is 1.
Returns
resid_dev : array
Deviance residuals as defined below
Notes
Binomial in general:
.. math::
resid\_dev_i = sign(Y_i - \mu_i) \sqrt{2 *
(Y_i * \log(Y_i / \mu_i) + (n_i - Y_i) *
\log(n_i - Y_i)/(n_i - \mu_i))/scale}
Since :math:`Y_i` and :math:`\mu_i` are transformed to :math:`[0,1]`
in Binomial.initialize, the following version is implemented:
.. math::
resid\_dev_i = sign(Y_i - \mu_i) \sqrt{ 2 *
n_i * (Y_i * \log(Y_i / \mu_i) + (1 - Y_i) *
\log((1 - Y_i) / (1 - \mu_i)))/scale}'

def resid_dev(self, endog, mu, scale=1.0):

    endog_mu = self._clean((endog / mu))
    n_endog_mu = self._clean(((1.0 - endog) / (1.0 - mu)))
    return (np.sign((endog - mu)) * np.sqrt((((2 * self.n) * ((endog * np.log(endog_mu)) + ((1.0 - endog) * np.log(n_endog_mu)))) / scale)))
