unspurious.calculators

Probability · Distributions

Negative Binomial Distribution Calculator

The negative binomial counts how many trials it takes to reach a target number of successes — not the first, but the r-th. Keep flipping until you have 3 heads; keep calling until you make 5 sales. Set the per-trial probability p and the target r, pick a trial number k, and get every probability at once, with the distribution drawn, the mean of r∕p, and a note on its two famous relatives: the geometric distribution and the overdispersed count.

X is the trial on which the r-th success occurs, so X is at least r. Set r = 1 and this becomes the geometric distribution. All five probabilities are listed below — the chip headlines and shades one.

Result

In plain English

The binomial fixes the number of trials and counts the successes; the negative binomial turns that around — it fixes the number of successes you are waiting for and counts the trials. The r-th success lands on trial k only if there were exactly r − 1 successes in the first k − 1 trials and then a success on trial k, which is where its formula comes from. With r = 1 it is just the wait for the first success — the geometric distribution — and for larger r it is the sum of r independent geometric waits, so its mean is r times bigger.

negative binomial distribution
The number of independent trials up to and including the r-th success, each trial succeeding with probability p. Here X = r, r + 1, ….
P(X = k), the probability mass
C(k − 1, r − 1) · pʳ · (1 − p)ᵏ⁻ʳ — the chance of r − 1 successes among the first k − 1 trials, then a final success.
mean = r∕p
The expected number of trials to collect r successes — r times the geometric’s 1∕p. The variance is r(1 − p)∕p² and the standard deviation √(r(1 − p))∕p.
geometric special case
Set r = 1 and the negative binomial is the geometric distribution: the wait for the very first success.
the overdispersed count
Re-parameterised by its mean, the negative binomial is the go-to model for count data whose variance exceeds its mean — the honest replacement for the Poisson when counts are clumpier than “mean = variance” allows.
two conventions
Some texts count the failures before the r-th success (X = 0, 1, 2, …) — which is what R’s and SciPy’s functions use. This calculator counts the trials; subtract r to convert.

Frequently asked

How do you calculate a negative binomial probability?

The probability that the r-th success falls on trial k is P(X = k) = C(k − 1, r − 1) · pʳ · (1 − p)ᵏ⁻ʳ. The combination counts the ways to place the first r − 1 successes among the first k − 1 trials; the powers give the probability of r successes and k − r failures; and the final trial must be the r-th success. For r = 3, p = 0.4 and k = 5 that is C(4, 2) × 0.4³ × 0.6² = 6 × 0.064 × 0.36 ≈ 0.138. This page also gives the cumulative “at most” and “at least” forms.

What is the difference between the binomial and negative binomial?

They swap what is fixed and what is counted. The binomial fixes the number of trials n and asks how many successes you get. The negative binomial fixes the number of successes r and asks how many trials that takes. “In 10 flips, how many heads?” is binomial; “how many flips to get 3 heads?” is negative binomial. Because you might wait a long time, the negative binomial has no upper limit on the number of trials, whereas the binomial caps at n.

How is the negative binomial related to the geometric distribution?

The geometric distribution is the special case r = 1 — the wait for the first success. The negative binomial for general r is the wait for the r-th, and it is exactly the sum of r independent geometric waits stacked end to end. That is why its mean, r∕p, is r times the geometric mean of 1∕p, and why its shape, skewed for small r, grows more symmetric (and approaches a normal) as r increases.

Why is the negative binomial used for overdispersed count data?

Counts are often modelled with the Poisson, but the Poisson forces the variance to equal the mean. Real counts — accidents, disease cases, words per document — usually vary more than that (overdispersion), because the underlying rate itself varies. The negative binomial, written in terms of its mean and a dispersion parameter, is a Poisson whose rate is allowed to wobble, so it has variance greater than its mean and fits clumpy counts far better. When a Poisson model’s residuals are too spread out, the negative binomial is the standard next step.