code: def _ll_nbp(y, X, beta, alph, Q):
      r"""
      Negative Binomial Log-likelihood -- type P
  
      References:
  
      Greene, W. 2008. "Functional forms for the negative binomial model
          for count data". Economics Letters. Volume 99, Number 3, pp.585-590.
      Hilbe, J.M. 2011. "Negative binomial regression". Cambridge University Press.
  
      Following notation in Greene (2008), with negative binomial heterogeneity
      parameter :math:`\alpha`:
  
      .. math::
  
          \lambda_i = exp(X\beta)\\
          \theta = 1 / \alpha \\
          g_i = \theta \lambda_i^Q \\
          w_i = g_i/(g_i + \lambda_i) \\
          r_i = \theta / (\theta+\lambda_i) \\
          ln \mathcal{L}_i = ln \Gamma(y_i+g_i) - ln \Gamma(1+y_i) + g_iln (r_i) + y_i ln(1-r_i)
      """
      mu = np.exp(np.dot(X, beta))
      size = 1 / alph * mu**Q
      prob = size / (size + mu)
      ll = nbinom.logpmf(y, size, prob)
      return ll
  
imports: from urllib.request import urlopen
  import numpy
  from numpy.testing import assert_almost_equal
  from scipy.special import digamma
  from scipy.stats import nbinom
  import pandas
  import patsy
  from statsmodels.base.model import GenericLikelihoodModel
  from statsmodels.base.model import GenericLikelihoodModelResults
label_desc: Use image node_id 1 for calling a global function with example usage: _ll_nbp(y, X, beta, alph, Q) and returns: ll