14. Common continuous distributions
Eight shapes cover almost everything continuous that probability touches. Three describe raw randomness, two generalise waiting times and proportions, and three arise from sampling a Normal — those last three are the backbone of hypothesis testing.
Uniform — every value equally likely
The simplest possible density: flat across an interval.
f(x) = \frac{1}{b-a} \quad \text{for } a \le x \le b, \qquad 0 \text{ otherwise}
The height is forced, not chosen: the area must be 1, so a rectangle of width b-a must have height \frac{1}{b-a}.
E[X] = \frac{a+b}{2}, \qquad \operatorname{Var}(X) = \frac{(b-a)^2}{12}
The mean is the midpoint, by symmetry. The 12 in the variance looks arbitrary but falls straight out of \int_a^b x^2 f(x)dx - \mu^2.
Story: rounding error, a random point on a line — and, crucially,
random.random(). The Uniform is the raw material every other distribution is
generated from (§11).
Exponential — waiting time until the next event
The time until the next rare event, when events arrive at constant rate \lambda.
f(x) = \lambda e^{-\lambda x} \quad (x \ge 0), \qquad F(x) = 1 - e^{-\lambda x}
E[X] = \frac{1}{\lambda}, \qquad \operatorname{Var}(X) = \frac{1}{\lambda^2}
Rate 5 per hour means an average wait of 1/5 hour. Note \sigma = 1/\lambda equals the mean — the Exponential is highly variable.
Memorylessness — the continuous twin of the Geometric's:
P(X > s + t \mid X > s) = P(X > t)
No matter how long you've already waited, the remaining wait has the same distribution. The bus is not "due". The Exponential is the only continuous distribution with this property, and that uniqueness is why it's the default model for lifetimes with no ageing.
Story: time until the next customer, next decay, next failure of a memoryless component.
Parameterisation warning. Some sources use the scale \beta = 1/\lambda instead of the rate. SciPy's
expon(scale=...)wants the scale. Mixing them up inverts your answer.
Normal — the bell curve
f(x) = \frac{1}{\sigma\sqrt{2\pi}}\exp\!\left(-\frac{(x-\mu)^2}{2\sigma^2}\right)
E[X] = \mu, \qquad \operatorname{Var}(X) = \sigma^2
The parameters are the mean and variance, which is unusually convenient.
Why it's everywhere: whenever you add up many small independent effects, their sum tends to this shape regardless of what you added. That's the Central Limit Theorem (§3), and it's the reason the Normal isn't just one distribution among many — it's the attractor that sums fall into.
Standardising. Any Normal becomes the standard one:
Z = \frac{X - \mu}{\sigma} \sim N(0, 1)
so a single table (or norm.cdf) serves every Normal. Worth memorising:
| Range | Probability |
|---|---|
| \mu \pm \sigma | 68.3% |
| \mu \pm 2\sigma | 95.4% |
| \mu \pm 3\sigma | 99.7% |
Sums of independent Normals are Normal, with means and variances adding — we proved this with characteristic functions two lessons ago.
Lognormal — when the effects multiply instead of adding
X is lognormal when \ln X is Normal. Equivalently, X = e^{Y} with Y \sim N(\mu, \sigma^2):
f(x) = \frac{1}{x\sigma\sqrt{2\pi}}\exp\!\left(-\frac{(\ln x - \mu)^2}{2\sigma^2}\right), \qquad x > 0
E[X] = e^{\mu + \sigma^2/2}, \qquad \operatorname{Var}(X) = \left(e^{\sigma^2} - 1\right)e^{2\mu + \sigma^2}
The parameters are not the mean and variance. \mu and \sigma describe \ln X, not X — the single most common error with this distribution. Note E[X] \neq e^{\mu}; the extra e^{\sigma^2/2} is there because exponentiating is convex, so the mean of the exponential exceeds the exponential of the mean (Jensen's inequality).
Why it's everywhere: the CLT says sums of many small independent effects go Normal. Take logs and the same argument says products of many small independent effects go lognormal — and multiplicative growth is the norm outside the laboratory. Incomes, house prices, city sizes, response latencies, file sizes and stock prices are all built by repeated proportional changes ("up 3% this year"), not by adding fixed increments.
That makes it the natural model for anything positive and right-skewed, which is most real measurements. §0.0's salary example — mean ₹88.9k against a median of ₹48k — is lognormal-shaped, and §8.3 derives lognormal asset prices from Brownian motion for exactly this reason: log-returns add, so prices multiply.
Consequences worth carrying: the distribution lives on (0,\infty) so it can never go negative (unlike a Normal fitted to prices); it is right-skewed with mode $< $ median $< $ mean, and the median is the clean one, e^{\mu} exactly; and a product of independent lognormals is lognormal, with the \mus and \sigma^2s adding — the multiplicative mirror of the Normal's own closure rule.
Gamma — waiting for the k-th event
The Exponential generalised: the wait until the k-th event, not the first.
f(x) = \frac{\lambda^k x^{k-1}e^{-\lambda x}}{\Gamma(k)} \quad (x \ge 0)
E[X] = \frac{k}{\lambda}, \qquad \operatorname{Var}(X) = \frac{k}{\lambda^2}
Set k = 1 and you're back to the Exponential exactly. For integer k it's literally a sum of k independent Exponentials, which makes the mean obvious.
\Gamma(k) is the gamma function, the factorial extended to non-integers: \Gamma(k) = (k-1)! when k is a positive integer.
Story: total time to serve k customers; also the standard flexible model for any positive, right-skewed quantity — rainfall, insurance claims.
Beta — a distribution over probabilities
Different in kind. Beta doesn't model a waiting time or a measurement — it models a proportion, so it lives only on [0, 1].
f(x) = \frac{x^{\alpha-1}(1-x)^{\beta-1}}{B(\alpha, \beta)} \quad (0 \le x \le 1)
E[X] = \frac{\alpha}{\alpha+\beta}, \qquad \operatorname{Var}(X) = \frac{\alpha\beta}{(\alpha+\beta)^2(\alpha+\beta+1)}
Its flexibility is remarkable for two parameters: \alpha = \beta = 1 gives the Uniform; \alpha, \beta > 1 gives a hump; \alpha, \beta < 1 gives a U-shape; unequal values skew it.
Story: uncertainty about a rate — a click-through rate, a batting average, a coin's bias. Read \alpha as "successes seen" and \beta as "failures seen". This is exactly why Beta is the conjugate prior for the Binomial in §7.
The three sampling distributions
These three don't describe raw data. They describe statistics computed from Normal samples, which is why they appear the moment you start testing hypotheses.
Chi-squared
The sum of k squared independent standard Normals:
Q = Z_1^2 + Z_2^2 + \cdots + Z_k^2 \sim \chi^2_k
E[Q] = k, \qquad \operatorname{Var}(Q) = 2k
It's a Gamma in disguise (k/2 shape, rate 1/2). Since it's built from squares it's non-negative and right-skewed.
Used for: anything about a variance — because sample variance is a sum of squared deviations. Also goodness-of-fit tests (§5).
Student's t
A standard Normal divided by the square root of an independent scaled chi-squared:
T = \frac{Z}{\sqrt{Q/k}} \sim t_k
Shaped like the Normal but with heavier tails. Those heavier tails are not cosmetic — they're the whole point. When you estimate \sigma from the data instead of knowing it, you've added a second source of uncertainty, and the t distribution is exactly the correction for it.
As k \to \infty, t_k \to N(0,1): with enough data your estimate of \sigma is good enough that the correction stops mattering. By k \approx 30 the two are already close.
Used for: testing a mean when \sigma is unknown — which is essentially always (§5).
F
The ratio of two independent chi-squareds, each divided by its degrees of freedom:
F = \frac{Q_1/k_1}{Q_2/k_2} \sim F_{k_1, k_2}
Used for: comparing two variances, and hence ANOVA (§5), where you compare variance between groups against variance within them.
How they relate
- Exponential = Gamma with k = 1
- Chi-squared = Gamma with shape k/2, rate 1/2
- t_k \to Normal as k \to \infty
- F_{1,k} = t_k^2
- Sum of k squared standard Normals = \chi^2_k
- Sum of independent Normals = Normal
- \ln(\text{Lognormal}) = Normal, so a product of independent lognormals is lognormal — the multiplicative counterpart of the line above
Worked example
Adult heights are N(170, 10^2) cm. Find P(X > 185) and the height exceeded by only 5% of people.
First part. Standardise:
Z = \frac{185 - 170}{10} = 1.5
P(X > 185) = P(Z > 1.5) = 1 - \Phi(1.5) = 1 - 0.9332 = 0.0668
About 6.7%. Sanity check: 185 is 1.5 SDs above the mean, and the 68–95–99.7 rule says ~16% lie above +1\sigma and ~2.3% above +2\sigma. Landing between them at 6.7% is right.
Second part. We want x with P(X > x) = 0.05, i.e. the 95th percentile. From the standard Normal, z_{0.95} = 1.645. Un-standardise:
x = \mu + z\sigma = 170 + 1.645(10) = 186.45 \text{ cm}
Note the two parts run in opposite directions: the first goes value \to probability (the CDF), the second probability \to value (the inverse CDF, or quantile function). Keeping those straight is most of the practical skill.
Doing it in Python
Same interface as the discrete ones, but .pdf() replaces .pmf(), and
.ppf() is the inverse CDF:
from scipy.stats import uniform, expon, norm, lognorm, gamma, beta, chi2, t, f
print("Uniform(0,4) mean", uniform.mean(0, 4), " var", round(uniform.var(0, 4), 4))
print("Expon(rate 5) mean", expon.mean(scale=1/5), " var", round(expon.var(scale=1/5), 4))
print("Normal(170,10) mean", norm.mean(170, 10), " var", norm.var(170, 10))
print("Lognormal(0,0.6) mean", round(lognorm.mean(0.6), 4), " median", round(lognorm.median(0.6), 4))
print("Gamma(k=3,rate=2) mean", round(gamma.mean(3, scale=1/2), 4))
print("Beta(2,5) mean", round(beta.mean(2, 5), 4), " (= 2/7)")
print("Chi2(5) mean", chi2.mean(5), " var", chi2.var(5), " (= k, 2k)")
print("t(10) var ", round(t.var(10), 4), " (> 1: heavier tails)")
The Lognormal, and the two traps that come with it — SciPy's parametrisation, and the gap between e^{\mu} and the mean:
import numpy as np
from scipy.stats import lognorm
mu, sigma = 0.0, 0.6 # these describe ln(X), NOT X
# SciPy wants s=sigma and scale=exp(mu). Getting this wrong is the usual bug.
X = lognorm(s=sigma, scale=np.exp(mu))
print(f"median e^mu = {np.exp(mu):.4f} (also X.median() = {X.median():.4f})")
print(f"mean e^(mu + sigma^2/2) = {np.exp(mu + sigma**2/2):.4f} (X.mean() = {X.mean():.4f})")
print(f"mode e^(mu - sigma^2) = {np.exp(mu - sigma**2):.4f}")
print("\nmode < median < mean -- right-skewed, always")
# Taking logs turns it back into a Normal, which is the definition.
sample = X.rvs(200_000, random_state=0)
print(f"\nmean of log(sample) = {np.log(sample).mean():.4f} (should be mu = {mu})")
print(f"sd of log(sample) = {np.log(sample).std():.4f} (should be sigma = {sigma})")
# Products of lognormals stay lognormal -- the multiplicative closure rule.
product = X.rvs(200_000, random_state=1) * X.rvs(200_000, random_state=2)
print(f"\nsd of log(product) = {np.log(product).std():.4f}"
f" (should be sqrt(2)*sigma = {np.sqrt(2)*sigma:.4f})")
The heights example, both directions:
from scipy.stats import norm
H = norm(loc=170, scale=10)
print("P(X > 185) =", round(1 - H.cdf(185), 4))
print("95th percentile =", round(H.ppf(0.95), 2), "cm")
# The 68-95-99.7 rule, verified
for k in (1, 2, 3):
inside = H.cdf(170 + k*10) - H.cdf(170 - k*10)
print(f"within {k} sd: {inside:.4%}")
Watch t converge to the Normal as the degrees of freedom grow — the reason "large sample" lets you stop worrying about it:
from scipy.stats import t, norm
print(f"{'df':>6} {'t 97.5th pct':>14} {'normal':>10}")
for df in (2, 5, 10, 30, 100, 1_000):
print(f"{df:>6} {t.ppf(0.975, df):>14.4f} {norm.ppf(0.975):>10.4f}")
At df = 2 the critical value is 4.30 versus the Normal's 1.96 — using the wrong one would make your confidence interval less than half as wide as it should be.
And the definitions of the sampling distributions, confirmed by simulation:
import numpy as np
rng = np.random.default_rng(0)
n = 200_000
k = 5
# Chi-squared: sum of k squared standard normals
Q = (rng.standard_normal((n, k)) ** 2).sum(axis=1)
print(f"chi2({k}): simulated mean {Q.mean():.3f} var {Q.var():.3f} (theory {k}, {2*k})")
# t: Z / sqrt(Q/k), with Z independent of Q
Z = rng.standard_normal(n)
T = Z / np.sqrt(Q / k)
print(f"t({k}): simulated var {T.var():.3f} (theory {k/(k-2):.3f})")
Your turn
1. Buses arrive on average every 10 minutes (Exponential). What's the probability of waiting more than 15 minutes?
2. IQ scores are N(100, 15^2). What fraction of people score above 130?
3. You've waited 20 minutes for that bus. What's the probability you wait more than 15 minutes more?
Solutions
1. Rate \lambda = 1/10 per minute. Use the survival function:
P(X > 15) = e^{-\lambda \cdot 15} = e^{-1.5} \approx 0.2231
About 22%.
2. Standardise: z = \frac{130 - 100}{15} = 2.
P(X > 130) = 1 - \Phi(2) \approx 0.0228
About 2.3% — the familiar "two standard deviations above the mean" figure, and where the conventional "gifted" threshold comes from.
3. By memorylessness, exactly the same as question 1:
P(X > 35 \mid X > 20) = P(X > 15) = e^{-1.5} \approx 0.2231
The 20 minutes you've already spent are irrelevant. This is genuinely counter-intuitive and it's the defining property of the Exponential.
It also tells you when the model is wrong. A bus on a timetable is not memoryless — waiting 20 minutes for a 10-minute service means something has gone badly wrong, and your expectation should update. Memorylessness fits processes with no ageing and no schedule: radioactive decay, yes; buses and machine parts, not really.
Check yourself in code
Work the heights example both directions and verify the 68–95–99.7 rule.
Print exactly this:
P(X > 185) = 0.0668
95th percentile = 186.45
within 1 sd: 0.6827
within 2 sd: 0.9545
Round the probability to 4 decimal places, the percentile to 2, and each coverage to 4.
from scipy.stats import norm
H = norm(loc=170, scale=10)
print("P(X > 185) =", round(1 - H.cdf(185), 4))
# Print the 95th percentile, then the coverage within 1 and 2 standard
# deviations of the mean.
from scipy.stats import norm
H = norm(loc=170, scale=10)
print("P(X > 185) =", round(1 - H.cdf(185), 4))
print("95th percentile =", round(H.ppf(0.95), 2))
for k in (1, 2):
inside = H.cdf(170 + k * 10) - H.cdf(170 - k * 10)
print(f"within {k} sd: {round(inside, 4)}")
Uniform, Exponential and Normal describe raw randomness. Gamma and Beta generalise waiting times and proportions. And Chi-squared, t and F all grow out of sampling a Normal — which is why they reappear the moment this course reaches hypothesis testing.
That closes §1. Next: what happens when two random variables vary together.