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 combinatorial functions, 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 \(n \in \mathbb{N}\) is defined as \[ \text{NegBinomial2}(n \, | \, \mu, \phi) = \binom{n + \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 \(n \sim \text{NegBinomial2}(n~|~\mu,\phi)\) are \[ \mathbb{E}[n] = \mu \ \ \ \text{ and } \ \ \ \text{Var}[n] = \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
n ~
neg_binomial_2
(mu, phi)
Increment target log probability density with neg_binomial_2_lpmf(n | mu, phi)
dropping constant additive terms.
13.2.3 Stan Functions
real
neg_binomial_2_lpmf
(ints n | 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 transformed data and generated quantities blocks. mu
must be less than \(2 ^ {29}\). For a description of argument and return types, see
section vectorized function signatures.