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: .
Bernoulli PMF and Moments
Here,
- =Probability of success
- =Probability of failure
- == p (mean)
- == p(1-p) (variance)
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 .
ThBinomial Probability Mass Function
where is the binomial coefficient (read: "$n$ choose $k$").
Why the Binomial Coefficient Appears
The binomial coefficient counts the number of distinct ways to arrange successes among trials. Each arrangement has probability (by independence). Summing over all arrangements gives the total probability.
Derivation of Mean and Variance
ThMean and Variance of Binomial
For :
Proof. Since with i.i.d.:
using the additivity of variance for independent random variables.
The variance is maximized when , giving .
Generating Function
Probability Generating Function
Here,
- =Probability generating function
- =Complex variable (|s| ≤ 1)
The MGF is , from which all moments can be derived.
Normal Approximation to the Binomial
ThNormal Approximation to Binomial
When is large and is not too close to 0 or 1:
The approximation improves as and . A continuity correction (replacing with ) significantly improves accuracy.
Rule of thumb: The normal approximation is adequate when and .
Continuity correction:
Poisson Approximation
When is large and is small (with fixed):
Poisson Approximation to Binomial
Here,
- =Expected number of successes (np)
- =Number of trials (large)
- =Success probability (small)
The Poisson approximation is appropriate when and , or and .
Worked Example: Quality Control
Example: Defective Items in a Batch
A quality control inspector checks items, each with defect probability . What is ?
Exact (binomial):
Normal approximation: ,
Poisson approximation:
The Poisson approximation is more accurate here because is small.
Worked Example: Coin Flipping
Example: Fair and Biased Coins
You flip a fair coin () 10 times. What is the probability of getting exactly 7 heads?
Mean: heads Variance: Standard deviation:
So getting 7 heads is standard deviations above the mean — unusual but not extreme.
Worked Example: A/B Testing
Example: Website Conversion Rate
An A/B test compares two versions of a landing page:
- Version A: 1,000 visitors, 120 conversions →
- Version B: 1,000 visitors, 156 conversions →
Under the binomial model:
- : ,
- : ,
Test statistic: where
-value — Version B has significantly higher conversion at .
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."