# Negative binomial distribution

In probability theory and statistics, the **negative binomial distribution** is a discrete probability distribution of the number of successes in a sequence of independent and identically distributed Bernoulli trials before a specified (non-random) number of failures (denoted *r*) occurs. For example, we can define that when we throw a dice and get a 6 it is a failure while rolling any other number is considered a success, and also choose r to be 3. We then throw the dice repeatedly until the third time the number 6 appears. In such a case, the probability distribution of the number of non-6s that appeared will be a negative binomial distribution.

Different texts adopt slightly different definitions for the negative binomial distribution. They can be distinguished by whether the support starts at k = 0 or at k = r, whether p denotes the probability of a success or of a failure, and whether r represents success or failure,[1] so it is crucial to identify the specific parametrization used in any given text. | |||

Probability mass function The orange line represents the mean, which is equal to 10 in each of these plots; the green line shows the standard deviation. | |||

Notation | |||
---|---|---|---|

Parameters |
r > 0 — number of failures until the experiment is stopped (integer, but the definition can also be extended to reals)p ∈ (0,1) — success probability in each experiment (real) | ||

Support |
k ∈ { 0, 1, 2, 3, … } — number of successes | ||

pmf | involving a binomial coefficient | ||

CDF | the regularized incomplete beta function | ||

Mean | |||

Mode | |||

Variance | |||

Skewness | |||

Ex. kurtosis | |||

MGF | |||

CF | |||

PGF | |||

Fisher information |

The **Pascal distribution** (after Blaise Pascal) and **Polya distribution** (for George Pólya) are special cases of the negative binomial distribution. A convention among engineers, climatologists, and others is to use "negative binomial" or "Pascal" for the case of an integer-valued stopping-time parameter *r*, and use "Polya" for the real-valued case.

For occurrences of "contagious" discrete events, like tornado outbreaks, the Polya distributions can be used to give more accurate models than the Poisson distribution by allowing the mean and variance to be different, unlike the Poisson. "Contagious" events have positively correlated occurrences causing a larger variance than if the occurrences were independent, due to a positive covariance term.

The term "negative binomial" is likely due to the fact that a certain binomial coefficient that appears in the formula for the probability mass function of the distribution can be written more simply with negative numbers [2].

## Definitions

Suppose there is a sequence of independent Bernoulli trials. Thus, each trial has two potential outcomes called "success" and "failure". In each trial the probability of success is *p* and of failure is (1 − *p*). We are observing this sequence until a predefined number *r* of failures have occurred. Then the random number of successes we have seen, *X*, will have the **negative binomial** (or **Pascal**) distribution:

When applied to real-world problems, outcomes of *success* and *failure* may or may not be outcomes we ordinarily view as good and bad, respectively. Suppose we used the negative binomial distribution to model the number of days a certain machine works before it breaks down. In this case "success" would be the result on a day when the machine worked properly, whereas a breakdown would be a "failure". If we used the negative binomial distribution to model the number of goal attempts an athlete makes before scoring *r* goals, though, then each unsuccessful attempt would be a "success", and scoring a goal would be "failure". If we are tossing a coin, then the negative binomial distribution can give the number of tails ("success") we are likely to encounter before we encounter a certain number of heads ("failure"). In the probability mass function below, *p* is the probability of success, and (1 − *p*) is the probability of failure.

### Probability mass function

The probability mass function of the negative binomial distribution is

where *k* is the number of successes, r is the number of failures, and *p* is the probability of success. Here the quantity in parentheses is the binomial coefficient, and is equal to

This quantity can alternatively be written in the following manner, explaining the name "negative binomial":

Note that by the last expression and the binomial series, for every 0 ≤ *p* < 1,

hence the terms of the probability mass function indeed add up to one.

To understand the above definition of the probability mass function, note that the probability for every specific sequence of *r* failures and *k* successes is (1 − *p*)* ^{r}p^{k}*, because the outcomes of the

*k*+

*r*trials are supposed to happen independently. Since the

*r*th failure always comes last, it remains to choose the

*k*trials with successes out of the remaining

*k*+

*r*− 1 trials. The above binomial coefficient, due to its combinatorial interpretation, gives precisely the number of all these sequences of length

*k*+

*r*− 1.

### Cumulative distribution function

The cumulative distribution function can be expressed in terms of the regularized incomplete beta function:

It can also be expressed in terms of the cumulative distribution function of the binomial distribution[3]:

### Alternative formulations

Some sources may define the negative binomial distribution slightly differently from the primary one here. The most common variations are where the random variable *X* is counting different things. These variations can be seen in the table here:

X is counting... |
Probability mass function | Formula | Alternate formula
(using equivalent binomial) |
Alternate formula
(simplified using: ) |
Support | |

1 | r failures, given k successes |
[4][5][6] | [7][8][9][10] | |||

2 | n trials, given k successes |
[5][10][11][12][13] | ||||

3 | k successes, given n trials |
This is the binomial distribution: |

Each of these definitions of the negative binomial distribution can be expressed in slightly different but equivalent ways. The first alternative formulation is simply an equivalent form of the binomial coefficient, that is: . The second alternate formulation somewhat simplifies the expression by recognizing that the total number of trials is simply the number of successes and failures, that is: . These second formulations may be more intuitive to understand, however they are perhaps less practical as they have more terms.

- The definition where
*X*is the number of*r***failures**that occur for a given number of*k***successes**. This definition is very similar to the primary definition used in this article, only that*k*successes and*r*failures are switched when considering what is being counted and what is given. Note however, that*p*still refers to the probability of "success". - The definition where
*X*is the number of*n***trials**that occur for a given number of*k***successes**. This definition is very similar to definition #2, only that*k*successes is given instead of*r*failures. Note however, that*p*still refers to the probability of "success".

- The definition of the negative binomial distribution can be extended to the case where the parameter
*r*can take on a positive real value. Although it is impossible to visualize a non-integer number of "failures", we can still formally define the distribution through its probability mass function. The problem of extending the definition to real-valued (positive)*r*boils down to extending the binomial coefficient to its real-valued counterpart, based on the gamma function:

- Now, after substituting this expression in the original definition, we say that
*X*has a negative binomial (or**Pólya**) distribution if it has a probability mass function: - Here
*r*is a real, positive number.

In negative binomial regression,[14] the distribution is specified in terms of its mean, , which is then related to explanatory variables as in linear regression or other generalized linear models. From the expression for the mean *m*, one can derive and . Then, substituting these expressions in the one for the probability mass function when *r* is real-valued, yields this parametrization of the probability mass function in terms of *m*:

The variance can then be written as . Some authors prefer to set , and express the variance as . In this context, and depending on the author, either the parameter *r* or its reciprocal *α* is referred to as the "dispersion parameter", "shape parameter" or "clustering coefficient",[15] or the "heterogeneity"[14] or "aggregation" parameter.[9] The term "aggregation" is particularly used in ecology when describing counts of individual organisms. Decrease of the aggregation parameter *r* towards zero corresponds to increasing aggregation of the organisms; increase of *r* towards infinity corresponds to absence of aggregation, as can be described by Poisson regression.

- Sometimes the distribution is parameterized in terms of its mean
*μ*and variance*σ*^{2}:

### Examples

#### Selling candy

Pat Collis is required to sell candy bars to raise money for the 6th grade field trip. There are thirty houses in the neighborhood, and Pat is not supposed to return home until five candy bars have been sold. So the child goes door to door, selling candy bars. At each house, there is a 0.6 probability of selling one candy bar and a 0.4 probability of selling nothing.

*What's the probability of selling the last candy bar at the* *n*th *house?*

Successfully selling candy enough times is what defines our stopping criterion (as opposed to failing to sell it), so *k* in this case represents the number of failures and *r* represents the number of successes. Recall that the NegBin(*r*, *p*) distribution describes the probability of *k* failures and *r* successes in *k* + *r* Bernoulli(*p*) trials with success on the last trial. Selling five candy bars means getting five successes. The number of trials (i.e. houses) this takes is therefore *k* + 5 = *n*. The random variable we are interested in is the number of houses, so we substitute *k* = *n* − 5 into a NegBin(5, 0.4) mass function and obtain the following mass function of the distribution of houses (for *n* ≥ 5):

*What's the probability that Pat finishes on the tenth house?*

*What's the probability that Pat finishes on or before reaching the eighth house?*

To finish on or before the eighth house, Pat must finish at the fifth, sixth, seventh, or eighth house. Sum those probabilities:

*What's the probability that Pat exhausts all 30 houses in the neighborhood?*

This can be expressed as the probability that Pat does not finish on the fifth through the thirtieth house:

Because of the rather high probability that Pat will sell to each house (60 percent), the probability of her NOT fulfilling her quest is vanishingly slim.

#### Length of hospital stay

Hospital length of stay is an example of real-world data that can be modelled well with a negative binomial distribution.[16]

## Properties

### Expectation

The expected total number of successes in a negative binomial distribution with parameters (*r*, *p*) is *rp*/(1 − *p*). To see this, imagine an experiment simulating the negative binomial is performed many times. That is, a set of trials is performed until *r* failures are obtained, then another set of trials, and then another etc. Write down the number of trials performed in each experiment: *a*, *b*, *c*, … and set *a* + *b* + *c* + … = *N*. Now we would expect about *Np* successes in total. Say the experiment was performed *n* times. Then there are *nr* failures in total. So we would expect *nr* = *N*(1 − *p*), so *N*/*n* = *r*/(1 − *p*). See that *N*/*n* is just the average number of trials per experiment. That is what we mean by "expectation". The average number of successes per experiment is *N*/*n* − *r* = *r*/(1 − *p*) − *r* = *rp*/(1 − *p*). This agrees with the mean given in the box on the right-hand side of this page.

### Variance

When counting the number of successes given the number *r* of failures, the variance is *rp*/(1 − *p*)^{2}.
When counting the number of successes before the *r*-th failure, the variance is *r*(1 − *p*)/*p*^{2}.

### Relation to the binomial theorem

Suppose *Y* is a random variable with a binomial distribution with parameters *n* and *p*. Assume *p* + *q* = 1, with *p*, *q* ≥ 0, then

Using Newton's binomial theorem, this can equally be written as:

in which the upper bound of summation is infinite. In this case, the binomial coefficient

is defined when *n* is a real number, instead of just a positive integer. But in our case of the binomial distribution it is zero when *k* > *n*. We can then say, for example

Now suppose *r* > 0 and we use a negative exponent:

Then all of the terms are positive, and the term

is just the probability that the number of failures before the *r*th success is equal to *k*, provided *r* is an integer. (If *r* is a negative non-integer, so that the exponent is a positive non-integer, then some of the terms in the sum above are negative, so we do not have a probability distribution on the set of all nonnegative integers.)

Now we also allow non-integer values of *r*. Then we have a proper negative binomial distribution, which is a generalization of the Pascal distribution, which coincides with the Pascal distribution when *r* happens to be a positive integer.

Recall from above that

- The sum of independent negative-binomially distributed random variables
*r*_{1}and*r*_{2}with the same value for parameter*p*is negative-binomially distributed with the same*p*but with*r*-value*r*_{1}+*r*_{2}.

This property persists when the definition is thus generalized, and affords a quick way to see that the negative binomial distribution is infinitely divisible.

## Related distributions

- The geometric distribution (on { 0, 1, 2, 3, ... }) is a special case of the negative binomial distribution, with

- The negative binomial distribution is a special case of the discrete phase-type distribution.
- The negative binomial distribution is a special case of discrete Compound Poisson distribution.

### Poisson distribution

Consider a sequence of negative binomial random variables where the stopping parameter *r* goes to infinity, whereas the probability of success in each trial, *p*, goes to zero in such a way as to keep the mean of the distribution constant. Denoting this mean as *λ*, the parameter *p* will be *p* = *λ*/(*r* + *λ*)

Under this parametrization the probability mass function will be

Now if we consider the limit as *r* → ∞, the second factor will converge to one, and the third to the exponent function:

which is the mass function of a Poisson-distributed random variable with expected value *λ*.

In other words, the alternatively parameterized negative binomial distribution converges to the Poisson distribution and *r* controls the deviation from the Poisson. This makes the negative binomial distribution suitable as a robust alternative to the Poisson, which approaches the Poisson for large *r*, but which has larger variance than the Poisson for small *r*.

### Gamma–Poisson mixture

The negative binomial distribution also arises as a continuous mixture of Poisson distributions (i.e. a compound probability distribution) where the mixing distribution of the Poisson rate is a gamma distribution. That is, we can view the negative binomial as a Poisson(*λ*) distribution, where *λ* is itself a random variable, distributed as a gamma distribution with shape = *r* and scale *θ* = *p*/(1 − *p*) or correspondingly rate *β* = (1 − *p*)/*p*.

To display the intuition behind this statement, consider two independent Poisson processes, “Success” and “Failure”, with intensities *p* and 1 − *p*. Together, the Success and Failure processes are equivalent to a single Poisson process of intensity 1, where an occurrence of the process is a success if a corresponding independent coin toss comes up heads with probability *p*; otherwise, it is a failure. If *r* is a counting number, the coin tosses show that the count of successes before the *r*th failure follows a negative binomial distribution with parameters *r* and *p*. The count is also, however, the count of the Success Poisson process at the random time *T* of the *r*th occurrence in the Failure Poisson process. The Success count follows a Poisson distribution with mean *pT*, where *T* is the waiting time for *r* occurrences in a Poisson process of intensity 1 − *p*, i.e., *T* is gamma-distributed with shape parameter *r* and intensity 1 − *p*. Thus, the negative binomial distribution is equivalent to a Poisson distribution with mean *pT*, where the random variate *T* is gamma-distributed with shape parameter *r* and intensity 1 − *p*. The preceding paragraph follows, because *λ* = *pT* is gamma-distributed with shape parameter *r* and intensity (1 − *p*)/*p*.

The following formal derivation (which does not depend on *r* being a counting number) confirms the intuition.

Because of this, the negative binomial distribution is also known as the **gamma–Poisson (mixture) distribution**.

Note: The negative binomial distribution was originally derived as a limiting case of the gamma-Poisson distribution.[17]

### Distribution of a sum of geometrically distributed random variables

If *Y*_{r} is a random variable following the negative binomial distribution with parameters *r* and *p*, and support {0, 1, 2, ...}, then *Y*_{r} is a sum of *r* independent variables following the geometric distribution (on {0, 1, 2, ...}) with parameter 1 − *p*. As a result of the central limit theorem, *Y*_{r} (properly scaled and shifted) is therefore approximately normal for sufficiently large *r*.

Furthermore, if *B*_{s+r} is a random variable following the binomial distribution with parameters *s* + *r* and 1 − *p*, then

In this sense, the negative binomial distribution is the "inverse" of the binomial distribution.

The sum of independent negative-binomially distributed random variables *r*_{1} and *r*_{2} with the same value for parameter *p* is negative-binomially distributed with the same *p* but with *r*-value *r*_{1} + *r*_{2}.

The negative binomial distribution is infinitely divisible, i.e., if *Y* has a negative binomial distribution, then for any positive integer *n*, there exist independent identically distributed random variables *Y*_{1}, ..., *Y*_{n} whose sum has the same distribution that *Y* has.

### Representation as compound Poisson distribution

The negative binomial distribution NB(*r*,*p*) can be represented as a compound Poisson distribution: Let {*Y _{n}*,

*n*∈ ℕ

_{0}} denote a sequence of independent and identically distributed random variables, each one having the logarithmic distribution Log(

*p*), with probability mass function

Let *N* be a random variable, independent of the sequence, and suppose that *N* has a Poisson distribution with mean λ = −*r* ln(1 − *p*). Then the random sum

is NB(*r*,*p*)-distributed. To prove this, we calculate the probability generating function *G _{X}* of

*X*, which is the composition of the probability generating functions

*G*and

_{N}*G*

_{Y1}. Using

and

we obtain

which is the probability generating function of the NB(*r*,*p*) distribution.

The following table describes four distributions related to the number of successes in a sequence of draws:

With replacements | No replacements | |
---|---|---|

Given number of draws | binomial distribution | hypergeometric distribution |

Given number of failures | negative binomial distribution | negative hypergeometric distribution |

### (a,b,0) class of distributions

The negative binomial along with the Poisson and binomial distributions is a member of the (a,b,0) class of distributions. All three of these distributions are special cases of the Panjer distribution. They are also members of the Natural exponential family.

## Statistical Inference

### Parameter estimation

#### MUVUE for *p*

*p*

Suppose *p* is unknown and an experiment is conducted where it is decided ahead of time that sampling will continue until *r* successes are found. A sufficient statistic for the experiment is *k*, the number of failures.

In estimating *p*, the minimum variance unbiased estimator is

#### Maximum likelihood estimation

The maximum likelihood estimate of *p* is

but this is a biased estimate. Its inverse (*r* + *k*)/*r*, is an unbiased estimate of 1/*p*, however.[18]

The maximum likelihood estimator only exists for samples for which the sample variance is larger than the sample mean.[19] The likelihood function for *N* iid observations (*k*_{1}, ..., *k*_{N}) is

from which we calculate the log-likelihood function

To find the maximum we take the partial derivatives with respect to *r* and *p* and set them equal to zero:

- and

where

- is the digamma function.

Solving the first equation for *p* gives:

Substituting this in the second equation gives:

This equation cannot be solved for *r* in closed form. If a numerical solution is desired, an iterative technique such as Newton's method can be used. Alternatively, the expectation–maximization algorithm can be used.[19]

## Occurrence and applications

### Waiting time in a Bernoulli process

For the special case where *r* is an integer, the negative binomial distribution is known as the **Pascal distribution**. It is the probability distribution of a certain number of failures and successes in a series of independent and identically distributed Bernoulli trials. For *k* + *r* Bernoulli trials with success probability *p*, the negative binomial gives the probability of *k* successes and *r* failures, with a failure on the last trial. In other words, the negative binomial distribution is the probability distribution of the number of successes before the *r*th failure in a Bernoulli process, with probability *p* of successes on each trial. A Bernoulli process is a discrete time process, and so the number of trials, failures, and successes are integers.

Consider the following example. Suppose we repeatedly throw a die, and consider a 1 to be a "failure". The probability of success on each trial is 5/6. The number of successes before the third failure belongs to the infinite set { 0, 1, 2, 3, ... }. That number of successes is a negative-binomially distributed random variable.

When *r* = 1 we get the probability distribution of number of successes before the first failure (i.e. the probability of the first failure occurring on the (*k* + 1)st trial), which is a geometric distribution:

### Overdispersed Poisson

The negative binomial distribution, especially in its alternative parameterization described above, can be used as an alternative to the Poisson distribution. It is especially useful for discrete data over an unbounded positive range whose sample variance exceeds the sample mean. In such cases, the observations are overdispersed with respect to a Poisson distribution, for which the mean is equal to the variance. Hence a Poisson distribution is not an appropriate model. Since the negative binomial distribution has one more parameter than the Poisson, the second parameter can be used to adjust the variance independently of the mean. See Cumulants of some discrete probability distributions.

An application of this is to annual counts of tropical cyclones in the North Atlantic or to monthly to 6-monthly counts of wintertime extratropical cyclones over Europe, for which the variance is greater than the mean.[20][21][22] In the case of modest overdispersion, this may produce substantially similar results to an overdispersed Poisson distribution.[23][24]

The negative binomial distribution is also commonly used to model data in the form of discrete sequence read counts from high-throughput RNA and DNA sequencing experiments.[25][26][27]

## History

This distribution was first studied in 1713, by Montmort, as the distribution of the number of trials required in an experiment to obtain a given number of successes.[28] It had previously been mentioned by Pascal.[29]

## See also

## References

- DeGroot, Morris H. (1986).
*Probability and Statistics*(Second ed.). Addison-Wesley. pp. 258–259. ISBN 0-201-11366-X. LCCN 84006269. OCLC 10605205. - user30490, Why is a "negative binomial" random variable called that?, URL (version: 2015-08-27): https://stats.stackexchange.com/q/169111
- Morris K W (1963),A note on direct and inverse sampling, Biometrika, 50, 544--545.
- "Mathworks: Negative Binomial Distribution".
- Cook, John D. "Notes on the Negative Binomial Distribution" (PDF).
- Saha, Abhishek. "Introduction to Probability / Fundamentals of Probability: Lecture 14" (PDF).
- W., Weisstein, Eric. "Negative Binomial Distribution".
*mathworld.wolfram.com*. - SAS Institute, "Negative Binomial Distribution",
*SAS(R) 9.4 Functions and CALL Routines: Reference, Fourth Edition*, SAS Institute, Cary, NC, 2016. - Crawley, Michael J. (2012).
*The R Book*. Wiley. ISBN 978-1-118-44896-0. - "Set theory: Section 3.2.5 – Negative Binomial Distribution" (PDF).
- "Randomservices.org, Chapter 10: Bernoulli Trials, Section 4: The Negative Binomial Distribution".
- "Stat Trek: Negative Binomial Distribution".
- Wroughton, Jacqueline. "Distinguishing Between Binomial, Hypergeometric and Negative Binomial Distributions" (PDF).
- Hilbe, Joseph M. (2011).
*Negative Binomial Regression*(Second ed.). Cambridge, UK: Cambridge University Press. ISBN 978-0-521-19815-8. - Lloyd-Smith, J. O. (2007). "Maximum Likelihood Estimation of the Negative Binomial Dispersion Parameter for Highly Overdispersed Data, with Applications to Infectious Diseases".
*PLoS ONE*.**2**(2): e180. doi:10.1371/journal.pone.0000180. PMC 1791715. PMID 17299582. - Carter, E.M., Potts, H.W.W. (4 April 2014). "Predicting length of stay from an electronic patient record system: a primary total knee replacement example".
*BMC Medical Informatics and Decision Making*.**14**: 26. doi:10.1186/1472-6947-14-26. PMC 3992140. PMID 24708853.CS1 maint: multiple names: authors list (link) - Greenwood, M.; Yule, G. U. (1920). "An inquiry into the nature of frequency distributions representative of multiple happenings with particular reference of multiple attacks of disease or of repeated accidents".
*J R Stat Soc*.**83**(2): 255–279. doi:10.2307/2341080. JSTOR 2341080. - Haldane, J. B. S. (1945). "On a Method of Estimating Frequencies".
*Biometrika*.**33**(3): 222–225. doi:10.1093/biomet/33.3.222. hdl:10338.dmlcz/102575. JSTOR 2332299. PMID 21006837. - Aramidis, K. (1999). "An EM algorithm for estimating negative binomial parameters".
*Australian & New Zealand Journal of Statistics*.**41**(2): 213–221. doi:10.1111/1467-842X.00075. - Villarini, G.; Vecchi, G.A.; Smith, J.A. (2010). "Modeling of the dependence of tropical storm counts in the North Atlantic Basin on climate indices".
*Monthly Weather Review*.**138**(7): 2681–2705. doi:10.1175/2010MWR3315.1. - Mailier, P.J.; Stephenson, D.B.; Ferro, C.A.T.; Hodges, K.I. (2006). "Serial Clustering of Extratropical Cyclones".
*Monthly Weather Review*.**134**(8): 2224–2240. doi:10.1175/MWR3160.1. - Vitolo, R.; Stephenson, D.B.; Cook, Ian M.; Mitchell-Wallace, K. (2009). "Serial clustering of intense European storms".
*Meteorologische Zeitschrift*.**18**(4): 411–424. doi:10.1127/0941-2948/2009/0393. - McCullagh, Peter; Nelder, John (1989).
*Generalized Linear Models*(Second ed.). Boca Raton: Chapman and Hall/CRC. ISBN 978-0-412-31760-6. - Cameron, Adrian C.; Trivedi, Pravin K. (1998).
*Regression analysis of count data*. Cambridge University Press. ISBN 978-0-521-63567-7. -
Robinson, M.D.; Smyth, G.K. (2007). "Moderated statistical tests for assessing differences in tag abundance".
*Bioinformatics*.**23**(21): 2881–2887. doi:10.1093/bioinformatics/btm453. PMID 17881408. - Love, Michael; Anders, Simon (October 14, 2014). "Differential analysis of count data – the DESeq2 package" (PDF). Retrieved October 14, 2014.
- Chen, Yunshun; Davis, McCarthy (September 25, 2014). "edgeR: differential expression analysis of digital gene expression data" (PDF). Retrieved October 14, 2014.
- Montmort PR de (1713) Essai d'analyse sur les jeux de hasard. 2
^{nd}ed. Quillau, Paris - Pascal B (1679) Varia Opera Mathematica. D. Petri de Fermat. Tolosae