'The log-likelihood function in terms of the fitted mean response.
Parameters
endog : array-like
Endogenous response variable
mu : array-like
Fitted mean response variable
iweights : array-like
1d array of weights. The default is 1.
scale : float, optional
Not used in the Binomial loglike.
Returns
llf : float
The value of the loglikelihood function evaluated at
(endog,mu,iweights,scale) as defined below.
Notes
If the endogenous variable is binary:
.. math::
llf = \sum_i (y_i * \log(\mu_i/(1-\mu_i)) + \log(1-\mu_i)) *
iweights_i
If the endogenous variable is binomial:
.. math::
llf = \sum_i iweights_i * (\ln \Gamma(n+1) -
\ln \Gamma(y_i + 1) - \ln \Gamma(n_i - y_i +1) + y_i *
\log(\mu_i / (n_i - \mu_i)) + n * \log(1 - \mu_i/n_i))
where :math:`y_i = Y_i * n_i` with :math:`Y_i` and :math:`n_i` as
defined in Binomial initialize.  This simply makes :math:`y_i` the
original number of successes.'

def loglike(self, endog, mu, iweights=1, scale=1.0):

    if ((np.shape(self.n) == ()) and (self.n == 1)):
        return np.sum((((endog * np.log((mu / (1 - mu)))) + np.log((1 - mu))) * iweights))
    else:
        y = (endog * self.n)
        return np.sum((((((special.gammaln((self.n + 1)) - special.gammaln((y + 1))) - special.gammaln(((self.n - y) + 1))) + (y * np.log((mu / (1 - mu))))) + (self.n * np.log((1 - mu)))) * iweights))
