TExcelTAD
Home › Statistics › Binomial and Poisson Distributions

Binomial and Poisson Distributions

A probability distribution lists every possible value of a random variable together with its probability. The normal distribution describes continuous measurements. For counts, two discrete distributions appear again and again: the binomial and the Poisson.

The binomial distribution

The binomial distribution counts the number of successes X in n independent trials, each with the same success probability p. Conditions ("BINS"):

  • Binary outcome: each trial is a success or a failure.
  • Independent trials.
  • Number of trials n is fixed.
  • Same probability p for every trial.
text
P(X = k) = C(n, k) × p^k × (1 − p)^(n − k)
mean = n × p          standard deviation = √(n × p × (1 − p))

C(n, k) ("n choose k") is the number of ways to choose which k of the n trials are successes.

A call centre knows that 30% of calls are about billing. Of the next 10 calls, how many will be about billing?

python · try it yourself
import math
from scipy import stats

n, p = 10, 0.30
print("k  P(X=k)  formula")
for k in range(0, 6):
    by_hand = math.comb(n, k) * p**k * (1 - p) ** (n - k)
    print(f"{k}  {stats.binom.pmf(k, n, p):.4f}  {by_hand:.4f}")

print(f"P(X <= 2) = {stats.binom.cdf(2, n, p):.4f}")
print(f"P(X >= 5) = {stats.binom.sf(4, n, p):.4f}")
print(f"mean = {stats.binom.mean(n, p):.1f}, sd = {stats.binom.std(n, p):.3f}")
k  P(X=k)  formula
0  0.0282  0.0282
1  0.1211  0.1211
2  0.2335  0.2335
3  0.2668  0.2668
4  0.2001  0.2001
5  0.1029  0.1029
P(X <= 2) = 0.3828
P(X >= 5) = 0.1503
mean = 3.0, sd = 1.449

For discrete distributions the function is called pmf (probability mass function) instead of pdf. Note P(X ≥ 5) = sf(4), because sf(k) gives P(X > k).

python · try it yourself
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats

k = np.arange(0, 11)
fig, ax = plt.subplots(figsize=(6, 3.2))
ax.bar(k, stats.binom.pmf(k, 10, 0.30), color="#2a78d6", width=0.6)
ax.set_xticks(k)
ax.set_xlabel("billing calls among the next 10")
ax.set_ylabel("probability")
plt.tight_layout()
plt.show()
print("most likely count:", k[np.argmax(stats.binom.pmf(k, 10, 0.30))])
most likely count: 3

The Poisson distribution

The Poisson distribution counts events in a fixed interval of time or space when events happen independently at a constant average rate λ (lambda): emails per hour, typos per page, potholes per kilometre.

text
P(X = k) = λ^k × e^(−λ) / k!
mean = λ          variance = λ

A small bakery receives on average 3.2 online orders per hour:

python · try it yourself
from scipy import stats

lam = 3.2
for k in range(0, 8):
    print(f"P(X = {k}) = {stats.poisson.pmf(k, lam):.4f}")
print(f"P(no orders in an hour)  = {stats.poisson.pmf(0, lam):.4f}")
print(f"P(more than 5 orders)    = {stats.poisson.sf(5, lam):.4f}")
print(f"95% of hours have at most {stats.poisson.ppf(0.95, lam):.0f} orders")
P(X = 0) = 0.0408
P(X = 1) = 0.1304
P(X = 2) = 0.2087
P(X = 3) = 0.2226
P(X = 4) = 0.1781
P(X = 5) = 0.1140
P(X = 6) = 0.0608
P(X = 7) = 0.0278
P(no orders in an hour)  = 0.0408
P(more than 5 orders)    = 0.1054
95% of hours have at most 6 orders

Checking a model against data

Do real counts follow a Poisson distribution? Compare observed frequencies with the model's expected frequencies. Here we simulate 200 hours of orders and compare:

python · try it yourself
import numpy as np
import pandas as pd
from scipy import stats

rng = np.random.default_rng(32)
orders = rng.poisson(3.2, size=200)
lam_hat = orders.mean()
print(f"estimated λ = {lam_hat:.3f}, sample variance = {orders.var(ddof=1):.3f}")

k = np.arange(0, 9)
table = pd.DataFrame({
    "observed": [(orders == v).sum() for v in k],
    "expected": (200 * stats.poisson.pmf(k, lam_hat)).round(1),
}, index=k)
print(table)
estimated λ = 3.190, sample variance = 3.431
   observed  expected
0         6       8.2
1        29      26.3
2        45      41.9
3        47      44.6
4        28      35.5
5        20      22.7
6        17      12.1
7         4       5.5
8         2       2.2

Observed and expected counts are close, and mean ≈ variance, which is the Poisson's signature. Real count data often has variance much larger than the mean ("overdispersion"), which means the Poisson model is too simple. You can test the fit formally with a chi-square goodness-of-fit test.

Binomial ≈ normal for large n

When n × p and n × (1 − p) are both reasonably large, the binomial distribution looks like a normal distribution with the same mean and standard deviation. That is exactly why the z-tests for proportions work:

python · try it yourself
import math
from scipy import stats

n, p = 400, 0.62
mu, sd = n * p, math.sqrt(n * p * (1 - p))
exact = stats.binom.sf(267, n, p)                     # P(X >= 268)
approx = stats.norm.sf(267.5, mu, sd)                  # with continuity correction
print(f"exact binomial P(X >= 268) = {exact:.4f}")
print(f"normal approximation       = {approx:.4f}")
exact binomial P(X >= 268) = 0.0215
normal approximation       = 0.0223

Test yourself

Which situation follows a binomial distribution?

  1. Number of customers arriving per hour
  2. Number of heads in 20 coin flips
  3. Height of adults
  4. Time until a bulb fails

What are the mean and variance of a Poisson distribution with λ = 4?

  1. 4 and 2
  2. 4 and 4
  3. 2 and 4
  4. 4 and 16

With stats.binom, how do you compute P(X ≥ 3)?

  1. binom.sf(3, n, p)
  2. binom.sf(2, n, p)
  3. binom.cdf(3, n, p)
  4. 1 - binom.pmf(3, n, p)