13.2 Negative Binomial Distribution (alternative parameterization)

Stan also provides an alternative parameterization of the negative binomial distribution directly using a mean (i.e., location) parameter and a parameter that controls overdispersion relative to the square of the mean. Section 3.13, below, provides a second alternative parameterization directly in terms of the log mean.

13.2.1 Probability Mass Function

The first parameterization is for \(\mu \in \mathbb{R}^+\) and \(\phi \in \mathbb{R}^+\), which for \(y \in \mathbb{N}\) is defined as \[ \text{NegBinomial2}(y \, | \, \mu, \phi) = \binom{y + \phi - 1}{y} \, \left( \frac{\mu}{\mu+\phi} \right)^{\!y} \, \left( \frac{\phi}{\mu+\phi} \right)^{\!\phi} \!. \]

The mean and variance of a random variable \(y \sim \text{NegBinomial2}(y~|~\mu,\phi)\) are \[ \mathbb{E}[Y] = \mu \ \ \ \text{ and } \ \ \ \text{Var}[Y] = \mu + \frac{\mu^2}{\phi}. \] Recall that \(\text{Poisson}(\mu)\) has variance \(\mu\), so \(\mu^2 / \phi > 0\) is the additional variance of the negative binomial above that of the Poisson with mean \(\mu\). So the inverse of parameter \(\phi\) controls the overdispersion, scaled by the square of the mean, \(\mu^2\).

13.2.2 Sampling Statement

y ~ neg_binomial_2(mu, phi)

Increment target log probability density with neg_binomial_2_lpmf( y | mu, phi) dropping constant additive terms.

13.2.3 Stan Functions

real neg_binomial_2_lpmf(ints y | reals mu, reals phi)
The negative binomial probability mass of n given location mu and precision phi.

real neg_binomial_2_cdf(ints n, reals mu, reals phi)
The negative binomial cumulative distribution function of n given location mu and precision phi.

real neg_binomial_2_lcdf(ints n | reals mu, reals phi)
The log of the negative binomial cumulative distribution function of n given location mu and precision phi.

real neg_binomial_2_lccdf(ints n | reals mu, reals phi)
The log of the negative binomial complementary cumulative distribution function of n given location mu and precision phi.

R neg_binomial_2_rng(reals mu, reals phi)
Generate a negative binomial variate with location mu and precision phi; may only be used in generated quantities block. mu must be less than \(2 ^ {29}\). For a description of argument and return types, see section 10.8.1.