The Negative Binomial Distribution

SD05 — Discrete Distributions

Author

Samer El Kababji

Course: Statistics and Probability for Data Science (DS14270).
Source deck: Samer El Kababji, SD05 — Discrete Distributions.

The negative binomial distribution reverses the binomial stopping rule: fix the number of successes and count how many failures occur first.

Counting failures before the rth success

In independent Bernoulli trials with constant success probability \(p\), let \(X\) be the number of failures before the \(r\)th success. Then

\[ P(X=x)=\binom{x+r-1}{r-1}p^r(1-p)^x, \qquad x=0,1,2,\ldots. \]

The last trial must be the \(r\)th success. Among the preceding \(x+r-1\) trials, choose the positions of the other \(r-1\) successes.

Code
r <- 5
p <- 0.20
x <- 0:20

formula_pmf <- choose(x + r - 1, r - 1) * p^r * (1 - p)^x
R_pmf <- dnbinom(x, size = r, prob = p)

head(data.frame(failures = x, formula_pmf, R_pmf), 8)
  failures formula_pmf      R_pmf
1        0  0.00032000 0.00032000
2        1  0.00128000 0.00128000
3        2  0.00307200 0.00307200
4        3  0.00573440 0.00573440
5        4  0.00917504 0.00917504
6        5  0.01321206 0.01321206
7        6  0.01761608 0.01761608
8        7  0.02214593 0.02214593
Code
sum(R_pmf)
[1] 0.5793257

The displayed sum is less than 1 only because the infinite support was truncated at 20 failures.

Pediatrician recruitment example

A pediatrician asks couples to participate until 5 agree. Each couple agrees with probability \(p=0.20\). If exactly 15 couples are asked, there were 10 failures before the fifth success:

\[ P(X=10)=\binom{14}{4}(0.2)^5(0.8)^{10}\approx0.034. \]

Code
r <- 5
p <- 0.20
failures <- 15 - r

c(
  formula = choose(14, 4) * p^5 * (1 - p)^10,
  R = dnbinom(failures, size = r, prob = p),
  at_most_15_couples = pnbinom(failures, size = r, prob = p)
)
           formula                  R at_most_15_couples 
         0.0343941          0.0343941          0.1642337 

The probability that the fifth agreement arrives by the 15th couple is \(P(X\leq10)\approx0.164\).

Mean and variance

For this failures-before-successes convention,

\[ E(X)=\frac{r(1-p)}p, \qquad \operatorname{Var}(X)=\frac{r(1-p)}{p^2}. \]

If instead \(T=X+r\) counts the total number of trials through the \(r\)th success, then \(E(T)=r/p\) and \(\operatorname{Var}(T)=\operatorname{Var}(X)\).

Code
r <- 5
p <- 0.20

mean_failures <- r * (1 - p) / p
variance_failures <- r * (1 - p) / p^2

c(
  mean_failures = mean_failures,
  mean_total_trials = mean_failures + r,
  variance = variance_failures,
  sd = sqrt(variance_failures)
)
    mean_failures mean_total_trials          variance                sd 
               20                25               100                10 

Quantiles and a simulation check (fictional extension)

Code
# Failures needed so there is at least 90% probability of having r successes
q90_failures <- qnbinom(0.90, size = 5, prob = 0.20)
q90_total_trials <- q90_failures + 5

set.seed(14270)
simulated_failures <- rnbinom(100000, size = 5, prob = 0.20)

c(
  q90_failures = q90_failures,
  q90_total_trials = q90_total_trials,
  simulated_mean = mean(simulated_failures),
  theoretical_mean = 5 * 0.8 / 0.2
)
    q90_failures q90_total_trials   simulated_mean theoretical_mean 
        33.00000         38.00000         19.97846         20.00000 

Do not confuse the counting conventions

Base R’s dnbinom(), pnbinom(), qnbinom(), and rnbinom() count failures before size successes. If a question gives the total trial number \(t\), convert it with \(x=t-r\).

Practice questions

  1. A sale occurs with probability \(0.25\) on each independent call. Find the probability of exactly 8 failures before the third sale.
  2. Find the probability that the third sale occurs by the 11th call.
  3. Find the expected number and variance of failures before the third sale.
  4. Find the expected total number of calls through the third sale.
  1. dnbinom(8, size = 3, prob = 0.25) gives approximately \(0.0704\).
  2. The condition is \(X\leq8\), so pnbinom(8, 3, 0.25) gives approximately \(0.5448\).
  3. The mean is \(3(0.75)/0.25=9\) and the variance is \(3(0.75)/0.25^2=36\).
  4. Add the three successes: \(E(T)=9+3=12\) calls.