'The Anscombe residuals for the negative binomial family
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_anscombe : array
The Anscombe residuals as defined below.
Notes
Anscombe residuals for Negative Binomial are the same as for Binomial
upon setting :math:`n=-\frac{1}{\alpha}`. Due to the negative value of
:math:`-\alpha*Y` the representation with the hypergeometric function
:math:`H2F1(x) =  hyp2f1(2/3.,1/3.,5/3.,x)` is advantageous
.. math::
resid_anscombe_i = \frac{3}{2} *
(Y_i^(2/3)*H2F1(-\alpha*Y_i) - \mu_i^(2/3)*H2F1(-\alpha*\mu_i))
/ (\mu_i * (1+\alpha*\mu_i) * scale^3)^(1/6)
Note that for the (unregularized) Beta function, one has
:math:`Beta(z,a,b) = z^a/a * H2F1(a,1-b,a+1,z)`'

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

    hyp2f1 = (lambda x: special.hyp2f1((2 / 3.0), (1 / 3.0), (5 / 3.0), x))
    return (((3 / 2.0) * (((endog ** (2 / 3.0)) * hyp2f1(((- self.alpha) * endog))) - ((mu ** (2 / 3.0)) * hyp2f1(((- self.alpha) * mu))))) / (((mu * (1 + (self.alpha * mu))) * (scale ** 3)) ** (1 / 6)))
