Skip to content
VibeFormer
Intermediate26 min

Geometric, Negative Binomial and Hypergeometric

Waiting times, counts until r successes, and sampling without replacement.

Geometric, Negative Binomial and Hypergeometric

Intuition first

Three distributions, each obtained by relaxing one assumption of the binomial.

The binomial fixes the number of trials and counts successes. Turn that around — fix the number of successes and count the trials needed — and you get the geometric (one success) and the negative binomial (rr successes).

The hypergeometric keeps trials fixed but drops independence: it samples without replacement, so each draw changes the composition of what remains. Drawing 5 cards from a deck is hypergeometric; the binomial would be wrong because the second card's probabilities depend on the first.

Knowing which of these applies is mostly a matter of two questions: is the number of trials fixed or random, and is sampling with or without replacement?

Choosing among them

DistributionFixedCountsReplacement
Binomialnn trialssuccesseswith
Geometric1 successtrials neededwith
Negative binomialrr successestrials neededwith
Hypergeometricnn drawssuccesseswithout

The geometric distribution

Number of independent trials until the first success:

XGeometric(p),p(k)=(1p)k1p,k=1,2,3,X \sim \text{Geometric}(p), \qquad p(k) = (1-p)^{k-1}p, \qquad k = 1, 2, 3, \dots E[X]=1p,Var(X)=1pp2\E[X] = \frac{1}{p}, \qquad \Var(X) = \frac{1-p}{p^2}
Mean of the geometric, by conditioningAdvanced

The elegant route avoids summing the series. Either the first trial succeeds, or it fails and the situation resets — the memoryless property in action.

E[X]=1psuccess first try+(1p)(1+E[X])failure, then start over\E[X] = \underbrace{1 \cdot p}_{\text{success first try}} + \underbrace{(1-p)\big(1 + \E[X]\big)}_{\text{failure, then start over}}

The second term says: one trial was consumed, and from there the expected additional wait is the same E[X]\E[X] as at the beginning. Expand:

E[X]=p+(1p)+(1p)E[X]=1+(1p)E[X]\E[X] = p + (1-p) + (1-p)\E[X] = 1 + (1-p)\E[X]

Collect terms:

E[X](1p)E[X]=1pE[X]=1E[X]=1p\E[X] - (1-p)\E[X] = 1 \quad\Longrightarrow\quad p\,\E[X] = 1 \quad\Longrightarrow\quad \E[X] = \frac{1}{p}

Three lines, no series manipulation. The same trick gives the variance and appears again in Markov-chain hitting times and in the RL Bellman equations, which have exactly this self-referential structure.

The geometric is the unique discrete memoryless distribution:

P(X>m+nX>m)=P(X>n)\Prob(X > m + n \mid X > m) = \Prob(X > n)

The negative binomial

Number of trials until the rr-th success:

XNegBin(r,p),p(k)=(k1r1)pr(1p)kr,k=r,r+1,X \sim \text{NegBin}(r, p), \qquad p(k) = \binom{k-1}{r-1}p^r(1-p)^{k-r}, \qquad k = r, r+1, \dots E[X]=rp,Var(X)=r(1p)p2\E[X] = \frac{r}{p}, \qquad \Var(X) = \frac{r(1-p)}{p^2}

A negative binomial is a sum of rr independent geometrics, which gives its mean and variance immediately by linearity and independence.

The hypergeometric

Population of NN items containing KK successes; draw nn without replacement:

p(k)=(Kk)(NKnk)(Nn)p(k) = \frac{\binom{K}{k}\binom{N-K}{n-k}}{\binom{N}{n}} E[X]=nKN,Var(X)=nKN(1KN)NnN1\E[X] = n\frac{K}{N}, \qquad \Var(X) = n\frac{K}{N}\left(1 - \frac{K}{N}\right)\frac{N-n}{N-1}
Why the correction factor appears, and when it vanishesAdvanced

Draws without replacement are negatively correlated: drawing a success makes the next draw slightly less likely to be a success, since one has been removed. Write X=i=1n1iX = \sum_{i=1}^n \mathbb{1}_i where 1i\mathbb{1}_i indicates a success on draw ii. Then

Var(X)=iVar(1i)+ijCov(1i,1j)\Var(X) = \sum_i \Var(\mathbb{1}_i) + \sum_{i \neq j}\Cov(\mathbb{1}_i, \mathbb{1}_j)

Each indicator is Bernoulli(K/N)(K/N) by symmetry, giving the binomial-like first term. The covariances are all negative and identical, and summing them produces exactly the factor NnN1\frac{N-n}{N-1}.

Two limiting checks:

  • n=1n = 1: the factor is N1N1=1\frac{N-1}{N-1} = 1. A single draw cannot depend on itself, so hypergeometric and binomial coincide.
  • n=Nn = N: the factor is 0. Drawing the whole population always yields exactly KK successes, so there is no variability at all.
  • NnN \gg n: the factor tends to 1, and the hypergeometric converges to Binomial(n,K/N)(n, K/N). Removing a few items from a huge population barely changes the composition.

The usual rule: use the binomial approximation when n0.05Nn \leq 0.05N.

Solved problem 1 · All three on one scenario

A box holds 20 components, 6 defective.

(a) Draw 5 without replacement — probability exactly 2 are defective. (b) Draw 5 with replacement — same question. (c) Drawing with replacement, probability the first defective appears on draw 4. (d) Drawing with replacement, probability the 3rd defective appears on draw 8.

Step 1 — part (a): hypergeometric

N=20N = 20, K=6K = 6, n=5n = 5, k=2k = 2.

P(X=2)=(62)(143)(205)\Prob(X = 2) = \frac{\binom{6}{2}\binom{14}{3}}{\binom{20}{5}}(62)=15,(143)=14×13×126=364,(205)=15,504\binom{6}{2} = 15, \qquad \binom{14}{3} = \frac{14 \times 13 \times 12}{6} = 364, \qquad \binom{20}{5} = 15{,}504P(X=2)=15×36415,504=5,46015,5040.35217\Prob(X = 2) = \frac{15 \times 364}{15{,}504} = \frac{5{,}460}{15{,}504} \approx 0.35217

Step 2 — part (b): binomial with p = 6/20

p=0.3p = 0.3P(X=2)=(52)(0.3)2(0.7)3=10×0.09×0.343=0.3087\Prob(X = 2) = \binom{5}{2}(0.3)^2(0.7)^3 = 10 \times 0.09 \times 0.343 = 0.3087

Step 3 — compare (a) and (b)

without replacement:0.35217with replacement:0.30870\text{without replacement}: 0.35217 \qquad \text{with replacement}: 0.30870

Here n/N=5/20=0.25n/N = 5/20 = 0.25, well above the 0.05 threshold, so the binomial approximation is poor — off by about 14% relative. The finite population correction is

NnN1=15190.789\frac{N-n}{N-1} = \frac{15}{19} \approx 0.789

so the hypergeometric variance is only 79% of the binomial's, concentrating probability nearer the mean of 1.51.5 and thus raising P(X=2)\Prob(X=2).

Step 4 — part (c): geometric

First success on trial 4 means three failures then a success:

P(X=4)=(0.7)3(0.3)=0.343×0.3=0.1029\Prob(X = 4) = (0.7)^3(0.3) = 0.343 \times 0.3 = 0.1029

Step 5 — part (d): negative binomial

Third success on trial 8: among the first 7 trials there must be exactly 2 successes, then trial 8 is a success.

P(X=8)=(72)(0.3)3(0.7)5\Prob(X = 8) = \binom{7}{2}(0.3)^3(0.7)^5(72)=21,(0.3)3=0.027,(0.7)5=0.16807\binom{7}{2} = 21, \qquad (0.3)^3 = 0.027, \qquad (0.7)^5 = 0.16807=21×0.027×0.16807=21×0.004537890.09530= 21 \times 0.027 \times 0.16807 = 21 \times 0.00453789 \approx 0.09530

Answer

(a) 0.3522\approx 0.3522 hypergeometric; (b) 0.3087\approx 0.3087 binomial; (c) 0.1029\approx 0.1029; (d) 0.0953\approx 0.0953.

With n/N=0.25n/N = 0.25 the with/without distinction matters materially.

python
from scipy import stats

# (a) hypergeometric: M = population, n = successes in population, N = draws
print(f"(a) hypergeom  {stats.hypergeom(M=20, n=6, N=5).pmf(2):.5f}")
print(f"(b) binomial   {stats.binom(n=5, p=0.3).pmf(2):.5f}")
print(f"(c) geometric  {stats.geom(p=0.3).pmf(4):.5f}")
print(f"(d) negbinom   {stats.nbinom(n=3, p=0.3).pmf(8 - 3):.5f}   # nbinom counts FAILURES")

# Variance: the finite population correction.
H = stats.hypergeom(M=20, n=6, N=5)
B = stats.binom(n=5, p=0.3)
fpc = (20 - 5) / (20 - 1)
print(f"\nhypergeom var {H.var():.5f}")
print(f"binomial var  {B.var():.5f}   x fpc {fpc:.4f} = {B.var()*fpc:.5f}")

# The approximation improves as N grows with K/N fixed.
print(f"\n{'N':>8}  hypergeom P(X=2)   binomial 0.30870")
for N in (20, 100, 1000, 100_000):
    print(f"{N:8d}  {stats.hypergeom(M=N, n=int(0.3*N), N=5).pmf(2):.5f}")

Exercise 1

A salesperson closes 20% of calls. Find the expected number of calls to the first sale, and the probability it takes more than 10 calls.

Show solution

XGeometric(0.2)X \sim \text{Geometric}(0.2).

E[X]=10.2=5 calls\E[X] = \frac{1}{0.2} = 5 \text{ calls}

For the tail, "more than 10 calls" means the first 10 all failed:

P(X>10)=(10.2)10=0.810\Prob(X > 10) = (1 - 0.2)^{10} = 0.8^{10}0.810=0.10737418240.10740.8^{10} = 0.1073741824 \approx 0.1074

So about a 10.7% chance of needing more than 10 calls.

The survival function has the clean closed form P(X>k)=(1p)k\Prob(X > k) = (1-p)^k, which is often easier than summing the PMF. Note the memorylessness: after 10 failures, the expected additional calls is still 5.

Exercise 2

A shipment of 500 items contains 25 defective. 20 are inspected. Should you use hypergeometric or binomial? Compute the probability of finding no defects both ways.

Show solution

Strictly hypergeometric, since inspection is without replacement. But check the rule of thumb:

nN=20500=0.040.05\frac{n}{N} = \frac{20}{500} = 0.04 \leq 0.05

so the binomial approximation is acceptable.

Hypergeometric, with N=500N = 500, K=25K = 25, n=20n = 20, k=0k = 0:

P(X=0)=(250)(47520)(50020)=(47520)(50020)\Prob(X = 0) = \frac{\binom{25}{0}\binom{475}{20}}{\binom{500}{20}} = \frac{\binom{475}{20}}{\binom{500}{20}}

This equals the product of sequential probabilities:

4755004744994564810.34122\frac{475}{500}\cdot\frac{474}{499}\cdots\frac{456}{481} \approx 0.34122

Binomial, with p=25/500=0.05p = 25/500 = 0.05:

P(X=0)=(0.95)200.35849\Prob(X = 0) = (0.95)^{20} \approx 0.35849

The two differ by about 0.017, or 5% relative — small enough for most purposes, and the direction is predictable: the finite population correction

500204990.962\frac{500-20}{499} \approx 0.962

reduces variance slightly, so the hypergeometric puts marginally less mass in the tail at k=0k=0.

Use the binomial if you want a quick number, the hypergeometric if the result feeds an acceptance decision where 5% matters.


Next: Gamma and Beta Distributions.