Skip to content

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.

What are you counting?

Adds the probability of a value from k up to this number.

Results

ProbabilityMeaningValue
P(X = 7)r-th success on exactly trial 70.1244
P(X ≤ 7)r-th success by trial 70.5801
P(X < 7)r-th success before trial 70.4557
P(X ≥ 7)r-th success on trial 7 or later0.5443
P(X > 7)r-th success after trial 70.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

Negative binomial probabilities for r = 3, p = 0.4, values 3 to 30
kP(X = k)P(X ≤ k)P(X ≥ k)
30.06400.06401.0000
40.11520.17920.9360
50.13820.31740.8208
60.13820.45570.6826
70.12440.58010.5443
80.10450.68460.4199
90.08360.76820.3154
100.06450.83270.2318
110.04840.88110.1673
120.03550.91660.1189
130.02550.94210.0834
140.01810.96020.0579
150.01270.97290.0398
160.00880.98170.0271
170.00600.98770.0183
180.00410.99180.0123
190.00280.99450.0082
200.00190.99640.0055
210.00120.99760.0036
220.00080.99840.0024
230.00050.99900.0016
240.00040.99930.0010
250.00020.99960.0007
260.00020.99970.0004
279.86 × 10−50.99980.0003
286.39 × 10−50.99990.0002
294.13 × 10−50.99990.0001
302.66 × 10−51.00007.40 × 10−5

How to Use the Negative Binomial Distribution Calculator

  1. 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. 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. 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. 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.

The two conventions (X = Y + r)
PropertyTrials: XFailures: Y
What it countsTrials up to and including the r-th successFailures before the r-th success
Possible valuesr, r + 1, r + 2, …0, 1, 2, …
Probability of a valueC(k − 1, r − 1) pr (1 − p)k−rC(y + r − 1, y) pr (1 − p)y
Meanr/pr(1 − p)/p
Variancer(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.

Related Tools

More in Statistics Calculators

See all Statistics Calculators