Calculators King

Probability

Negative Binomial Distribution Calculator

Compute the probability of k failures before r successes, name that convention, and give the mean r times (1 minus p) over p.

Worksheet

Press Calculate to see the result.

Compute the probability of k failures before r successes, name that convention, and give the mean r times (1 minus p) over p.

What this calculator answers

The negative binomial on this page counts the failures that occur before a fixed number of successes. You decide that you need r successes, each trial succeeds with probability p, and k is how many failures show up along the way. That is different from a binomial count, where the number of trials is fixed, and different from a geometric count of trials until the first success. When the combination is small it is converted to an ordinary number and multiplied through. When it is too large for a safe integer, the probability is computed in log space with the log-gamma function so the result does not overflow.

The combination C(k + r − 1, k) is an exact integer. If that integer fits in a safe JavaScript number, the probability is the integer times p^r times (1 − p)^k. Otherwise the exact integer is displayed in full or scientific form and the probability uses log-gamma. Supporting counts and intermediate terms sit under the headline so a reader can see what was divided by what. When a checkbox or a tail setting changes the divisor or the rejection region, that choice appears in the steps rather than vanishing into a silent default.

The formula, written out

Negative binomial, failures before r successes uses this relationship.

P(X = k) = C(k + r − 1, k) × p^r × (1 − p)^k, mean = r(1 − p)/p

  • r. The fixed number of successes you are waiting for.
  • k. The number of failures observed before the r-th success.
  • p. The success probability on each trial.
  • C(k + r − 1, k). The number of sequences with that many failures and r − 1 successes before the last success.

The trial that produces the r-th success must be a success, and the preceding trials must contain exactly r − 1 successes and k failures. The number of such sequences is C(k + r − 1, k). Each has probability p^r (1 − p)^k. The expected number of failures before r successes is r times (1 − p) / p. The algebra is the named textbook identity for this worksheet. Intermediate products and quotients appear in order so a calculator and a pencil can agree to the displayed rounding. If a neighbouring page uses a different divisor or a continuity correction, that page says so on its own ticket.

A full worked example

Example loaded in the worksheet

The form is prefilled with a small example so every arithmetic step can be checked by hand. Change one field after you finish the walkthrough and confirm the ticket moves the way the formula predicts.

This page counts failures before r successes. It does not count the trial number of the last success, and it does not count failures only in the geometric sense. r = 5 successes and k = 3 failures, so the stopping trial is number 8. The combination C(7, 3) equals 35.

The combination 35 fits in a safe integer, so the probability is that integer times 0.4^5 times 0.6^3, which equals 0.0774. The mean number of failures is r(1 − p) / p = 5 × 0.6 / 0.4 = 7.5. The variance is that mean divided by p, which equals 18.75.

The expected number of trials, failures plus the 5 successes, would be 12.5. The headline mean is the failure count only. p was required to sit in (0, 1]. A zero success probability would make the wait for 5 successes infinite.

Figures from the worked example
P(X = k)0.0774
Combination C(k + r − 1, k)35
Mean failures7.5
Variance18.75

A second situation

A large combination evaluated in log space

This page counts failures before r successes. It does not count the trial number of the last success, and it does not count failures only in the geometric sense. r = 30 successes and k = 30 failures, so the stopping trial is number 60. The combination C(59, 30) equals 59,132,290,782,430,712.

The combination 59,132,290,782,430,712 is larger than a safe integer, or the direct power overflowed, so the probability was computed in log space with the log-gamma function. The log probability is −2.970277 and the probability is 0.0513. The mean number of failures is r(1 − p) / p = 30 × 0.5 / 0.5 = 30. The variance is that mean divided by p, which equals 60.

The expected number of trials, failures plus the 30 successes, would be 60. The headline mean is the failure count only. p was required to sit in (0, 1]. A zero success probability would make the wait for 30 successes infinite.

Figures from the worked example
P(X = k)0.0513
Combination C(k + r − 1, k)59,132,290,782,430,712
Mean failures30
Variance60

A small example multiplies a modest combination by the powers of p and 1 − p directly. A large example keeps the combination as an exact integer for display and moves the probability into log space, because converting that integer to an ordinary number would lose digits and can overflow. The second example changes the feature that this formula is sensitive to, and the ticket shows the new figure beside the same definition. That contrast is the fastest way to see which input owns the movement.

What moves when the input moves

The number of failures before the fifth success moved from 3 to 6. The headline result went from 0.0774 to 0.1003.

The nudged inputs

This page counts failures before r successes. It does not count the trial number of the last success, and it does not count failures only in the geometric sense. r = 5 successes and k = 6 failures, so the stopping trial is number 11. The combination C(10, 6) equals 210.

The combination 210 fits in a safe integer, so the probability is that integer times 0.4^5 times 0.6^6, which equals 0.1003. The mean number of failures is r(1 − p) / p = 5 × 0.6 / 0.4 = 7.5. The variance is that mean divided by p, which equals 18.75.

The expected number of trials, failures plus the 5 successes, would be 12.5. The headline mean is the failure count only. p was required to sit in (0, 1]. A zero success probability would make the wait for 5 successes infinite.

Figures from the worked example
P(X = k)0.1003
Combination C(k + r − 1, k)210
Mean failures7.5
Variance18.75

How to read the result

Read k as a failure count, starting at 0. Read the mean as the expected number of failures, not the expected number of trials. The expected number of trials would be the mean failures plus r. Say the unit, the sample size or contract terms, and the formula name in the same sentence as the figure. A number without those three pieces invites a later reader to invent a definition that this page never used.

Write the result with its unit, the inputs that produced it, and the name of the formula. Write the result with its unit, the inputs that produced it, and the name of the formula. If the ticket shows a decision sentence, quote the alpha and the tail with it. If the ticket shows a money or dose figure, quote the rate and the schedule that produced it.

Assumptions that have to stay true

  • Trials are independent with a constant success probability.
  • You stop when the r-th success occurs.
  • k counts failures before that stopping time, not the total number of trials.
  • r is a positive whole number.

If an assumption above is false, do not average the discomfort away. Change the worksheet or change the question. A correct arithmetic step on the wrong model is still the wrong answer for the decision you are trying to make.

Mistakes that change the answer

  • Using the trials-until-r-successes formula and still calling k a failure count. The powers and the mean both shift.
  • Converting a huge combination to a JavaScript number before multiplying. Digits are lost.
  • Setting r = 1 and expecting the geometric mean 1/p. With r = 1 this page's mean is (1 − p)/p, the expected failure count.
  • Letting p sit outside 0 to 1, or letting p equal 0, which makes the wait infinite.

Where a different calculator is the honest choice

Use the geometric calculator for the trial number of the first success. Use the binomial calculator when n is fixed and the success count is random. Use the combination calculator when you only need C(k + r − 1, k) and not the probability. Related links under the essay open pages that keep their own formulas instead of hiding a mode switch inside this ticket.

When the job changes, move to a page built for that job: Geometric Distribution Calculator, Binomial Distribution Calculator, Combination Calculator.

Check yourself

What is the probability of 3 failures before the 5th success when p = 0.4, and what is the mean number of failures?

C(7, 3) = 35, and 35 × 0.4^5 × 0.6^3 = 0.0774. The mean number of failures is 5 × 0.6 / 0.4 = 7.5. k counts failures before r successes.

Using the result in a sentence

Sales calls until a quota of yes answers, inspections until a quota of passes, and dice until a fixed number of sixes are the stories this convention matches. Keep the count, the unit, and the assumption list beside any copy of the number that leaves this browser tab.

A success probability that changes with the trial number, or a stopping rule that is not the r-th success, is outside this formula. Very large powers can underflow the displayed probability to 0 even when the log probability is finite. Pair the headline with the steps before you staff a route, set a grade boundary, or compare two contracts from a single number.

Questions people ask next

01What definition does the Negative Binomial Distribution Calculator commit to?

This page uses Negative binomial, failures before r successes: P(X = k) = C(k + r − 1, k) × p^r × (1 − p)^k, mean = r(1 − p)/p. The trial that produces the r-th success must be a success, and the preceding trials must contain exactly r − 1 successes and k failures. The number of such sequences is C(k + r − 1, k). Each has probability p^r (1 − p)^k. The expected number of failures before r successes is r times (1 − p) / p. If a textbook uses a different divisor, a different continuity correction, or a different rounding rule, the last digits can move, so the definition is printed above the result. The worksheet asks for Successes r, Success probability p, Failures k before those successes, and it refuses a blank that the formula cannot interpret. Keep that printed definition in the sentence you write next to the figure so a later reader can rebuild the arithmetic without guessing which convention you chose.

02How should the worked example be read out loud?

In the loaded example the p(x = k) is 0.0774. Read k as a failure count, starting at 0. Read the mean as the expected number of failures, not the expected number of trials. The expected number of trials would be the mean failures plus r. Say the unit and the count before you say whether the number is large or small. Read the steps in order rather than jumping to the headline, because the intermediate terms are where a swapped percent and proportion usually hide. If the ticket shows both a primary figure and a comparison figure, name which one you are quoting.

03What is the fastest way to get a misleading result?

Using the trials-until-r-successes formula and still calling k a failure count. The powers and the mean both shift. A success probability that changes with the trial number, or a stopping rule that is not the r-th success, is outside this formula. Very large powers can underflow the displayed probability to 0 even when the log probability is finite. A second common failure is leaving a checkbox or tail setting in the wrong state and then treating the number as if the default had matched your plan. Reset the example, change one input, and confirm the ticket moves in the direction the formula predicts before you trust a live run.

04When should I leave this page for a different calculator?

Use the geometric calculator for the trial number of the first success. Use the binomial calculator when n is fixed and the success count is random. Use the combination calculator when you only need C(k + r − 1, k) and not the probability. The related links under the essay go to those worksheets, which keep their own formulas instead of hiding them in a mode switch. If the question changed from a summary to a test, from a payment to a refinance, or from a raw score to a percentile, switch pages rather than forcing this ticket to answer a job it was not built for.

05What belongs in the sentence next to the number?

C(7, 3) = 35, and 35 × 0.4^5 × 0.6^3 = 0.0774. The mean number of failures is 5 × 0.6 / 0.4 = 7.5. k counts failures before r successes. Name the formula, the sample size or the inputs, and the unit before you compare the figure with someone else's. A bare number without those three pieces cannot be audited when a score, a rate, or a lab value is challenged later. Store the inputs beside the result whenever the figure will travel into a report.