Negative Binomial distribution
Story
We perform a series of Bernoulli trials with probability \(\beta/(1+\beta)\) of success. The number of failures, \(y\), before we get \(\alpha\) successes is Negative Binomially distributed.
An equivalent story is this: Draw a parameter \(\lambda\) out of a Gamma distribution with parameters \(\alpha\) and \(\beta\). Then draw a number \(y\) out of a Poisson distribution with parameter \(\lambda\). Then \(y\) is Negative Binomially distributed with parameters \(\alpha\) and \(\beta\). For this reason, the Negative Binomial distribution is sometimes called the GammaPoisson distribution.
Example
Bursty gene expression can give mRNA count distributions that are Negative Binomially distributed. Here, “success” is that a burst in gene expression stops. In this case, the parameter \(1/\beta\) is the mean number of transcripts in a burst of expression. The parameter \(\alpha\) is related to the frequency of the bursts. If multiple bursts are possible within the lifetime of mRNA, then \(\alpha > 1\). Then, the number of “failures” is the number of mRNA transcripts that are made in the characteristic lifetime of mRNA.
Parameters
There are two parameters: \(\alpha\), the desired number of successes, and \(\beta\), which is the mean of the \(\alpha\) identical Gamma distributions that give the Negative Binomial. The probability of success of each Bernoulli trial is given by \(\beta/(1+\beta)\).
Support
The NegativeBinomial distribution is supported on the set of nonnegative integers.
Probability mass function
Generally speaking, \(\alpha\) need not be an integer, so we may write the PMF as
See the notes below for other parametrizations.
Moments
Mean: \(\displaystyle{\frac{\alpha}{\beta}}\)
Variance: \(\displaystyle{\frac{\alpha(1+\beta)}{\beta^2}}\)
Usage
Package 
Syntax 

NumPy 

NumPy with (µ, φ) parametrization 

SciPy 

SciPy with (µ, φ) parametrization 

Stan 

Stan with (µ, φ) parametrization 

Notes
The Negative Binomial distribution may be parametrized such that the probability mass function is
These parameters are related to the parametrization above by \(\phi = \alpha\) and \(\mu = \alpha/\beta\). In the limit of \(\phi\to\infty\), which can be taken for the PMF, the Negative Binomial distribution becomes Poisson with parameter \(\mu\). This also gives meaning to the parameters \(\mu\) and \(\phi\); \(\mu\) is the mean of the Negative Binomial, and \(\phi\) controls extra width of the distribution beyond Poisson. The smaller \(\phi\) is, the broader the distribution.
In this parametrization, the pertinent moments are
Mean: \(\displaystyle{\mu}\)
Variance: \(\displaystyle{\mu\left(1 + \frac{\mu}{\phi}\right)}\).
In Stan, the Negative Binomial distribution using the \((\mu,\phi)\) parametrization is called neg_binomial_2
.
SciPy and NumPy use yet another parametrization. The PMF for SciPy is
The parameter \(1p\) is the probability of success of a Bernoulli trial (as defined in the story above). The parameters are related to the others we have defined by \(n=\alpha=\phi\) and \(p=\beta/(1+\beta) = \phi/(\mu+\phi)\). In this parametrization, the pertinent moments are
Mean: \(\displaystyle{n\,\frac{1p}{p}}\)
Variance: \(\displaystyle{n\,\frac{1p}{p^2}}\).
Note that Wikipedia uses this parametrization except defining \(p\) to be the probability of failure of a Bernoulli trial, in accordance with the story above.
PMF and CDF plots
In the αβ formulation:
In the µφ formulation: