Binomial Distribution
Probability Distributions
Counting Successes in Fixed Trials
The binomial distribution answers a simple but profound question: if I repeat the same experiment times, how many times will I succeed?
- Quality control — number of defective items in a batch of 100
- Medical trials — patients responding to treatment out of 50 enrolled
- Finance — days the market goes up out of 252 trading days
- A/B testing — conversions out of 1,000 visitors
The binomial is the bridge between individual probability and aggregate statistics.
The Bernoulli Trial
Definition
A Bernoulli trial is a random experiment with exactly two outcomes: success (with probability ) and failure (with probability ). A random variable representing a single trial has:
This is the Bernoulli distribution: .
From Bernoulli to Binomial
Definition
Let be i.i.d. Bernoulli() random variables. The binomial random variable counts the total number of successes:
We write .
Derivation of Mean and Variance
The variance is maximized when , giving .
Generating Function
The MGF is , from which all moments can be derived.
Normal Approximation to the Binomial
Rule of thumb: The normal approximation is adequate when and .
Continuity correction:
Poisson Approximation
When is large and is small (with fixed):
The Poisson approximation is appropriate when and , or and .
Worked Example: Quality Control
Worked Example: Coin Flipping
Worked Example: A/B Testing
Relationship to Other Distributions
| Distribution | Relationship to Binomial |
|---|---|
| Bernoulli | Special case: |
| Poisson | Limit as , , |
| Normal | Limit as , , |
| Negative Binomial | Counts trials until successes (different parameterization) |
| Hypergeometric | Sampling without replacement (vs. with replacement for binomial) |
Python Implementation
import numpy as np
from scipy import stats
import matplotlib.pyplot as plt
np.random.seed(42)
# Binomial distribution: n=20, p=0.4
n, p = 20, 0.4
x = np.arange(0, n+1)
pmf = stats.binom.pmf(x, n, p)
print(f"Binomial(n={n}, p={p})")
print(f"Mean: {stats.binom.mean(n, p):.1f}")
print(f"Variance: {stats.binom.var(n, p):.2f}")
print(f"Std Dev: {stats.binom.std(n, p):.2f}")
print(f"P(X=8): {stats.binom.pmf(8, n, p):.4f}")
print(f"P(X<=8): {stats.binom.cdf(8, n, p):.4f}")
# Normal approximation comparison
mu, sigma = n*p, np.sqrt(n*p*(1-p))
x_norm = np.linspace(0, n, 100)
pdf_norm = stats.norm.pdf(x_norm, mu, sigma)
fig, axes = plt.subplots(1, 2, figsize=(12, 5))
# PMF vs normal approximation
axes[0].bar(x, pmf, alpha=0.7, label=f'Binomial({n},{p})')
axes[0].plot(x_norm, pdf_norm, 'r-', lw=2, label=f'Normal({mu:.1f},{sigma:.2f})')
axes[0].set_xlabel('k')
axes[0].set_ylabel('P(X=k)')
axes[0].set_title('Binomial vs Normal Approximation')
axes[0].legend()
# Effect of p
for p_val, color in [(0.2, '#ef4444'), (0.5, '#6366f1'), (0.8, '#22c55e')]:
pmf_p = stats.binom.pmf(x, n, p_val)
axes[1].bar(x, pmf_p, alpha=0.6, label=f'p={p_val}', color=color)
axes[1].set_xlabel('k')
axes[1].set_ylabel('P(X=k)')
axes[1].set_title('Effect of Success Probability')
axes[1].legend()
plt.tight_layout()
plt.savefig('binomial_distribution.png', dpi=150)
plt.show()
Key Takeaways
Counts successes in independent Bernoulli trials:
PMF: ,
Mean: ; Variance:
Normal approximation valid when and (with continuity correction)
Poisson approximation valid when is large and is small
The binomial is the foundation of hypothesis testing for proportions and confidence intervals
"The binomial distribution is the discrete analog of the normal distribution — and like the normal, it appears everywhere."