Negative Binomial Distribution Calculator
Find the probability that the r-th success arrives on a given trial, by a given trial or later — counting either trials up to the r-th success or failures before it, as your textbook or R does. The calculator shows the formula, the mean and variance, the matching R call, a probability table and a bar chart. Free, no sign-up.
Adds the probability of a value from k up to this number.
Results
| Probability | Meaning | Value |
|---|---|---|
| P(X = 7) | r-th success on exactly trial 7 | 0.1244 |
| P(X ≤ 7) | r-th success by trial 7 | 0.5801 |
| P(X < 7) | r-th success before trial 7 | 0.4557 |
| P(X ≥ 7) | r-th success on trial 7 or later | 0.5443 |
| P(X > 7) | r-th success after trial 7 | 0.4199 |
7.5
Mean (r/p)
11.25
Variance (r(1 − p)/p²)
3.3541
Standard deviation
7
Median
How this was calculated
P(X = k) = C(k − 1, r − 1) × p^r × (1 − p)^(k − r) = C(6, 2) × 0.4^3 × (1 − 0.4)^4 = 15 × 0.4^3 × (1 − 0.4)^4 = 0.1244
The cumulative probability is the regularised incomplete beta function: P(at most 4 failures) = I_p(r, 4 + 1) = I_0.4(3, 5) = 0.5801.
In R: dnbinom(4, 3, 0.4) = 0.1244 and pnbinom(4, 3, 0.4) = 0.5801. R's size is r and it counts failures before the r-th success, so the r-th success on trial 7 is 4 failures.
Counting failures instead (Y = X − r), the mean is 4.5 and the variance is the same, 11.25. P(X = 7) equals P(Y = 4).
R can also take the mean number of failures instead of p: dnbinom(x, size = 3, mu = 4.5) gives the same distribution, since prob = size / (size + mu) = 0.4.
Probability distribution
| k | P(X = k) | P(X ≤ k) | P(X ≥ k) |
|---|---|---|---|
| 3 | 0.0640 | 0.0640 | 1.0000 |
| 4 | 0.1152 | 0.1792 | 0.9360 |
| 5 | 0.1382 | 0.3174 | 0.8208 |
| 6 | 0.1382 | 0.4557 | 0.6826 |
| 7 | 0.1244 | 0.5801 | 0.5443 |
| 8 | 0.1045 | 0.6846 | 0.4199 |
| 9 | 0.0836 | 0.7682 | 0.3154 |
| 10 | 0.0645 | 0.8327 | 0.2318 |
| 11 | 0.0484 | 0.8811 | 0.1673 |
| 12 | 0.0355 | 0.9166 | 0.1189 |
| 13 | 0.0255 | 0.9421 | 0.0834 |
| 14 | 0.0181 | 0.9602 | 0.0579 |
| 15 | 0.0127 | 0.9729 | 0.0398 |
| 16 | 0.0088 | 0.9817 | 0.0271 |
| 17 | 0.0060 | 0.9877 | 0.0183 |
| 18 | 0.0041 | 0.9918 | 0.0123 |
| 19 | 0.0028 | 0.9945 | 0.0082 |
| 20 | 0.0019 | 0.9964 | 0.0055 |
| 21 | 0.0012 | 0.9976 | 0.0036 |
| 22 | 0.0008 | 0.9984 | 0.0024 |
| 23 | 0.0005 | 0.9990 | 0.0016 |
| 24 | 0.0004 | 0.9993 | 0.0010 |
| 25 | 0.0002 | 0.9996 | 0.0007 |
| 26 | 0.0002 | 0.9997 | 0.0004 |
| 27 | 9.86 × 10−5 | 0.9998 | 0.0003 |
| 28 | 6.39 × 10−5 | 0.9999 | 0.0002 |
| 29 | 4.13 × 10−5 | 0.9999 | 0.0001 |
| 30 | 2.66 × 10−5 | 1.0000 | 7.40 × 10−5 |
How to Use the Negative Binomial Distribution Calculator
- 1. Choose what you count. Trials needed to reach the r-th success (X = r, r + 1, …) or failures before the r-th success (Y = 0, 1, 2, …). R, SciPy and many statistics books use the second; many introductory courses use the first.
- 2. Enter r and p. r is the number of successes you are waiting for, a whole number; p is the probability of success on each independent trial.
- 3. Enter k. The trial on which the r-th success happens (or the number of failures), and optionally an upper end for a range.
- 4. Read the results. Equal, at most, fewer than, at least and more than, with the formula filled in, the mean, variance and median, the equivalent R call, and a table and bar chart.
Two Parameterizations of the Negative Binomial
The negative binomial describes how long you wait for a fixed number of successes in independent trials with the same success probability p. It is the geometric distribution generalised from the first success to the r-th, and the two textbook definitions differ only in what is counted.
| Property | Trials: X | Failures: Y |
|---|---|---|
| What it counts | Trials up to and including the r-th success | Failures before the r-th success |
| Possible values | r, r + 1, r + 2, … | 0, 1, 2, … |
| Probability of a value | C(k − 1, r − 1) pr (1 − p)k−r | C(y + r − 1, y) pr (1 − p)y |
| Mean | r/p | r(1 − p)/p |
| Variance | r(1 − p)/p² | r(1 − p)/p² |
| Software | — | R's dnbinom, pnbinom, qnbinom; SciPy's nbinom |
To switch conventions subtract r: the r-th success on trial 7 with r = 3 is 4 failures, so P(X = 7) = P(Y = 4), and the means differ by exactly r. The calculator prints this conversion with your numbers, including the R call: in R, size is r and prob is p, and dnbinom(4, 3, 0.4) answers "third success on trial 7".
Worked Example: Survey Calls
A researcher phones households until three agree to be interviewed, and each agrees with probability 0.4. Counting trials, the chance the third agreement comes on exactly the seventh call is C(6, 2) × 0.4³ × 0.6⁴ = 15 × 0.064 × 0.1296 = 0.1244. The chance of finishing by call 7 is 0.5801, on call 7 or later 0.5443, and after call 7 0.4199.
The mean is r/p = 3/0.4 = 7.5 calls with variance 3 × 0.6 / 0.4² = 11.25, so the standard deviation is 3.3541, and the median is 7 calls. Counting failures instead, the mean is 4.5 refusals before the third agreement, and R's pnbinom(4, 3, 0.4) returns the same 0.5801.
A check against the binomial
Finishing by call 7 means at least 3 successes in the first 7 calls, so the cumulative probability equals P(Binomial(7, 0.4) ≥ 3) = 0.5801. The negative binomial asks "how many trials?" where the binomial asks "how many successes in a fixed number of trials?" — the same events seen from two sides.
Frequently Asked Questions
- Which parameterization of the negative binomial should I use?
- Use the one your course or software defines. If X counts trials it starts at r and has mean r/p; if Y counts failures it starts at 0 and has mean r(1 − p)/p. The answers differ by exactly r, so state which one you used. Switch the calculator between them and compare.
- How do I find the probability that the r-th success happens on trial k?
- Choose which r − 1 of the first k − 1 trials are successes, then require a success on trial k: C(k − 1, r − 1) × pr × (1 − p)k−r. With r = 3, p = 0.4 and k = 7 that is 15 × 0.064 × 0.1296 = 0.1244.
- How do I use R's dnbinom for the number of trials?
- R's dnbinom(x, size, prob) counts failures before the size-th success. Pass x = k − r: the third success on trial 7 is dnbinom(4, 3, 0.4) = 0.1244, and pnbinom(4, 3, 0.4) = 0.5801 is the probability it comes by trial 7.
- How is the negative binomial related to the geometric distribution?
- The geometric distribution is the special case r = 1: waiting for the first success. A negative binomial variable is also the sum of r independent geometric variables, which is why the mean and the variance are r times the geometric ones.
- Why does R accept a non-integer size and a mu argument?
- In statistics for count data the negative binomial is also used as a model with variance greater than the mean, where size does not have to be a whole number and mu is the mean. This calculator keeps to whole numbers of successes; it does print the mu that corresponds to your p, since prob = size / (size + mu).
- Is the negative binomial memoryless?
- No. Only the geometric (r = 1) is: after some successes, what is left to wait for is a shorter negative binomial wait, so the distribution of the remaining trials depends on how many successes you still need.