Negative binomial distribution
Negative binomial distribution: the number of trials needed to reach r successes. With the default parameters (successes needed r = 3, probability of success p = 0.4) its mean is 7.5 and its standard deviation 3.3541. Use the simulator below to draw samples and see it take shape.
Simulate it
Change the parameters, then draw random samples. The bars are the samples; the dots are the exact probabilities. With more samples the bars settle onto it.
Samples to draw
What is the negative binomial distribution?
The negative binomial generalises the geometric distribution: it counts the trials needed to collect r successes, when each trial succeeds with probability p. How many sales calls to make 3 sales? How many inspections to find 5 defects?
It is also the standard model for count data that varies more than a Poisson allows (overdispersion), such as the number of accidents per driver or sequencing reads per gene, because it can be written as a Poisson whose rate itself varies.
Where it is used
- Calls needed to close r sales.
- Items inspected until r defects are found.
- Free throws taken until a player has made r.
- Overdispersed counts: accidents, hospital visits, species counts, where the variance is larger than the mean.
Shape and parameters
With r = 1 it is the geometric distribution. As r grows the distribution becomes more bell-shaped, centred near r/p, with the variance r(1 − p)/p² always larger than for a Poisson with the same mean.
What it assumes
- Independent trials with the same success probability p.
- You stop when the r-th success happens.
How it relates to other distributions
- Geometric distribution: The special case r = 1.
- Poisson distribution: A Poisson whose rate varies from case to case, as a gamma, gives a negative binomial.
- Binomial distribution: The binomial fixes the number of trials; the negative binomial fixes the number of successes.
Common mistakes
- Confusing the 'trials until r successes' form used here with the 'failures before r successes' form used by Excel, SciPy and R.
- Using a Poisson for count data whose variance is clearly larger than its mean.
How to work it out
- 1
The probability mass function (the formula that gives the shape):
- 2
Its mean (the long-run average) and variance (the spread):
- 3
Worked example with the default parameters (successes needed r = 3, probability of success p = 0.4): With r = 3 and p = 0.4, what is the probability that all 3 successes have happened within 6 trials?
LaTeX source of the formulas on this page
\[ P(X=k)=\binom{k-1}{r-1}p^{r}(1-p)^{k-r} \]
\[ \mu = \frac{r}{p},\qquad \sigma^2 = \frac{r(1-p)}{p^2} \]
\[ \text{answer} = 0.4557 \]At a glance
| Property | Value |
|---|---|
| Type | Discrete (counts) |
| Parameters | successes needed r; probability of success p |
| Possible values | r, r + 1, r + 2, … |
| Mean | 7.5 |
| Variance | 11.25 |
| Standard deviation | 3.3541 |
| Example (successes needed r = 3, probability of success p = 0.4) | With r = 3 and p = 0.4, what is the probability that all 3 successes have happened within 6 trials? Answer: 0.4557. |
How to compute it in Excel, Python and R
| Tool | Function |
|---|---|
| Excel / Google Sheets | =NEGBINOM.DIST(k - r, r, p, FALSE) (counts failures) |
| Python (SciPy) | scipy.stats.nbinom.pmf(k - r, r, p) (counts failures) |
| R | dnbinom(k - r, r, p) (counts failures) |
Questions
What is the negative binomial distribution used for?
The number of trials needed to reach r successes. Typical uses: Calls needed to close r sales. Items inspected until r defects are found. Free throws taken until a player has made r.
What are the mean and variance of the negative binomial distribution?
Mean: μ = (r)/(p). Variance: σ² = (r(1-p))/(p²).
What does the negative binomial distribution assume?
Independent trials with the same success probability p. You stop when the r-th success happens.
How do I calculate it in Excel?
=NEGBINOM.DIST(k - r, r, p, FALSE) (counts failures)
How is the negative binomial distribution related to other distributions?
Geometric distribution: The special case r = 1. Poisson distribution: A Poisson whose rate varies from case to case, as a gamma, gives a negative binomial. Binomial distribution: The binomial fixes the number of trials; the negative binomial fixes the number of successes.