Bernoulli and Binomial Distributions
Single trials and counts of successes: PMF derivation, moments, and the normal approximation.
Assumes you know
Bernoulli and Binomial Distributions
Intuition first
A Bernoulli trial is one yes/no experiment: a coin flip, a click, a component passing inspection. One parameter, , the probability of success.
A binomial counts successes across independent Bernoulli trials with the same . How many heads in 10 flips, how many of 500 visitors convert, how many of 20 components pass.
Everything about the binomial follows from one observation: it is a sum of independent Bernoullis. The mean follows by linearity, the variance by independence, and the PMF by counting which arrangements of successes are possible. No new machinery is needed — which is why this is the right place to start with named distributions.
The assumptions are worth naming, because they are what break in practice: fixed , independent trials, constant . Correlated trials or drifting produce overdispersion, and a binomial model will then understate uncertainty.
Bernoulli
Deriving the Bernoulli momentsAdvanced
For the variance, note that because and . So , and
The variance is maximised at , where it equals , and vanishes at or — a certain outcome has no variability. This is why estimating a proportion near 0.5 requires the largest sample, and why the sample-size formula in the splits lesson used as a worst case.
Binomial
| Symbol | Meaning | Read aloud |
|---|---|---|
| n | Number of independent trials (fixed in advance) | n |
| p | Probability of success on each trial | p |
| k | Number of successes observed | k |
| C(n,k) | Number of ways to arrange k successes among n trials | n choose k |
Mean and variance from the Bernoulli decompositionAdvanced
Write with each independent.
Mean, by linearity — no independence needed:
Variance. Here independence is required, so that all covariance terms vanish:
Contrast with the direct route, which requires evaluating
and manipulating factorials. The decomposition into indicators avoids all of it — the same technique that solved the envelope problem in the expectation lesson.
MGF, also immediate from the decomposition. A single Bernoulli has , and MGFs of independent sums multiply:
From which it follows at once that for independent terms with the same — the MGFs multiply to give the same form with exponent .
Solved problem 1 · Quality inspection
A factory produces components with a 4% defect rate. A sample of 20 is inspected. Find the probability of (a) exactly 1 defective, (b) at most 1 defective, (c) at least 2 defective. Also give the mean and standard deviation.
Step 1 — identify the distribution and check assumptions
Fixed , constant , and components assumed independent. So .
Step 2 — exactly one defective
Step 3 — zero defectives
Step 4 — at most one
Step 5 — at least two, by complement
Note carefully: , not . The latter would wrongly exclude .
Step 6 — mean and standard deviation
Answer
; ; . Mean defectives, .
Solved problem 2 · When to use the normal approximation
A website has a 12% conversion rate. Of 500 visitors, what is the probability that more than 70 convert?
Step 1 — exact setup
, and we want .
Step 2 — check the approximation conditions
Both comfortably satisfied, so a normal approximation is appropriate.
Step 3 — matching moments
Step 4 — apply the continuity correction
is integer-valued and the normal is continuous. corresponds to the normal area above , not above 71 — the correction splits the gap between adjacent integers:
Step 5 — look up the tail
Step 6 — compare with the exact binomial
The exact value is . The approximation with continuity correction gives — an error of about 0.001.
Without the correction, using , we would get — an error of about , ten times worse.
Answer
About , against an exact . The continuity correction reduces the error roughly tenfold and costs nothing.
When the binomial model is wrong
| Violation | What happens | Use instead |
|---|---|---|
| Sampling without replacement from a small population | changes between draws | Hypergeometric |
| Trials are correlated | Variance exceeds | Beta-binomial |
| varies across trials | Overdispersion | Beta-binomial, or mixed model |
| not fixed in advance | Different sample space | Negative binomial or Poisson |
| large, small, moderate | Binomial still correct but awkward | Poisson approximation |
import numpy as np
from scipy import stats
# Worked example 1, exact.
X = stats.binom(n=20, p=0.04)
print(f"P(X=1) {X.pmf(1):.5f}")
print(f"P(X<=1) {X.cdf(1):.5f}")
print(f"P(X>=2) {X.sf(1):.5f} <- sf(1) = 1 - F(1), NOT sf(2)")
print(f"mean {X.mean():.3f} sd {X.std():.4f}")
# Worked example 2: exact vs normal, with and without continuity correction.
Y = stats.binom(n=500, p=0.12)
mu, sd = 60, np.sqrt(52.8)
exact = Y.sf(70)
with_cc = stats.norm.sf((70.5 - mu) / sd)
without_cc = stats.norm.sf((71 - mu) / sd)
print(f"\nexact {exact:.5f}")
print(f"normal + cc {with_cc:.5f} error {abs(with_cc-exact):.5f}")
print(f"normal, no cc {without_cc:.5f} error {abs(without_cc-exact):.5f}")
# Verify Var = np(1-p) empirically, and show what overdispersion looks like.
rng = np.random.default_rng(0)
indep = rng.binomial(20, 0.04, 200_000)
print(f"\nindependent trials: var {indep.var():.4f} theory {20*0.04*0.96:.4f}")
p_varying = rng.beta(2, 48, 200_000) # p drifts around 0.04
over = rng.binomial(20, p_varying)
print(f"p varies by batch: var {over.var():.4f} <- overdispersed")Exercise 1
A basketball player makes 70% of free throws. What is the probability she makes exactly 8 of 10?
Show solutionHide solution
.
About 23.3%. Note this is the single most likely value after : the mode of a binomial is near , and .
Exercise 2
In 100 coin flips of a fair coin, use the normal approximation to find the probability of between 45 and 55 heads inclusive.
Show solutionHide solution
, so
Conditions: and ✓.
Applying the continuity correction, "between 45 and 55 inclusive" becomes the interval :
The exact binomial value is — agreement to four decimal places, because makes the binomial perfectly symmetric and the normal approximation is at its best.
Without the correction, using , you would get and — an error of about 4.6 percentage points.
Next: Geometric, Negative Binomial and Hypergeometric, which relax the binomial's assumptions one at a time.