Understanding the negative binomial distribution calculator — concept and principle
This calculator gives probabilities for the negative binomial distribution: how long you wait, in trials or failures, until the r-th success in repeated independent trials with the same success chance p. Use it for questions such as "how many sales calls until the third sale" or "how many free throws until the fifth make", and for exact, cumulative and tail probabilities.
How it is calculated
With k failures before the r-th success:
P(k) = C(k + r − 1, r − 1) · p^r · (1 − p)^k, k = 0, 1, 2, …
- r: successes needed; p: success probability per trial (between 0 and 1).
- X can count total trials (X = k + r) or only the failures (X = k). The calculator converts trials to failures first.
- Mean of failures r(1 − p)/p; mean of trials r/p. Variance r(1 − p)/p² either way.
- Cumulative probabilities are computed with the regularized incomplete beta function.
The principle
For the r-th success to land on trial k + r, two things must happen. The last trial must be a success (probability p), and the first k + r − 1 trials must contain exactly r − 1 successes and k failures in any order. The number of such orders is C(k + r − 1, r − 1), and each order has probability p^(r−1)(1 − p)^k because trials are independent. Multiplying gives the formula. With r = 1 it becomes the geometric distribution.
Worked example
Default inputs: r = 3, p = 0.4, X counts total trials, X = 8.
- Failures before the 3rd success: k = 8 − 3 = 5.
- C(7, 2) = 21; p³ = 0.064; 0.6⁵ = 0.07776.
- P(X = 8) = 21 × 0.064 × 0.07776 = 0.104509.
- P(X ≤ 8) = 0.684605, so P(X > 8) = 0.315395; P(X < 8) = 0.580096 and P(X ≥ 8) = 0.419904.
- Mean = 3 ÷ 0.4 = 7.5 trials; variance = 3 × 0.6 ÷ 0.16 = 11.25; standard deviation = 3.3541.
| Probability of success per trial p | P(X = x) |
|---|---|
| 0.1 | 0.0124003 |
| 0.2 | 0.0550502 |
| 0.3 | 0.0952957 |
| 0.4 | 0.104509 |
| 0.5 | 0.0820313 |
| 0.6 | 0.0464486 |
| 0.8 | 0.00344064 |
How to read the result
P(X = x) is the chance that the r-th success happens exactly on that trial. P(X ≤ x) is the chance you are done by then, which is useful for planning ("how likely am I to need no more than 8 attempts?"). A large P(X > x) warns that the wait often runs longer. The mean shows the typical wait; a standard deviation that is large relative to the mean means waiting times vary a lot.
Common mistakes
- Mixing up the two conventions. "Trial number" and "number of failures" differ by r.
- Using it when p changes from trial to trial or trials influence each other.
- Confusing it with the binomial distribution, which counts successes in a fixed number of trials.
- Entering p as a percentage (40) instead of a probability (0.4).
Frequently asked questions
What is the difference between the negative binomial and geometric distributions?
The geometric distribution is the special case r = 1: the wait for the first success.
Why is the variance the same in both conventions?
Trials equal failures plus the constant r, and adding a constant shifts the mean but not the spread.
Can X be smaller than r?
Not when counting trials. You need at least r trials to get r successes, so the smallest value is r.
Sources: Weisstein, E. W., "Negative Binomial Distribution", Wolfram MathWorld