Student's t-Distribution
When we estimate a population mean from a sample, we usually don't know the population standard deviation σ and have to use the sample standard deviation s instead. That extra uncertainty means the standardised mean
t = (x̄ − μ) / (s / √n)does not follow the standard normal distribution exactly. It follows Student's t-distribution with n − 1 degrees of freedom (df). The distribution was published in 1908 by William Gosset under the pen name "Student" while he worked on small samples at a brewery.
Shape
The t-distribution looks like the standard normal: bell-shaped, symmetric around 0. But it has heavier tails: extreme values are more likely, reflecting the extra uncertainty from estimating σ. The fewer degrees of freedom, the heavier the tails. As df grows, s becomes a reliable estimate of σ and the t-distribution approaches the standard normal.
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
x = np.linspace(-5, 5, 400)
fig, ax = plt.subplots(figsize=(6.5, 3.5))
ax.plot(x, stats.norm.pdf(x), color="#0b0b0b", linewidth=2, linestyle="--", label="standard normal")
for df, color in [(1, "#eb6834"), (4, "#1baf7a"), (30, "#2a78d6")]:
ax.plot(x, stats.t.pdf(x, df), color=color, linewidth=2, label=f"t, df={df}")
ax.legend(frameon=False)
plt.tight_layout()
plt.show()
print("Tail probability P(T > 2) for growing df:")
for df in [1, 4, 30, 1000]:
print(f" df={df:4d}: {stats.t.sf(2, df):.4f}")
print(f" normal : {stats.norm.sf(2):.4f}")Tail probability P(T > 2) for growing df:
df= 1: 0.1476
df= 4: 0.0581
df= 30: 0.0273
df=1000: 0.0229
normal : 0.0228
Critical values grow for small samples
Because the tails are heavier, you have to go further from 0 to cut off the same tail area. Here are the two-tailed 95% critical values t_(0.025, df) compared with the normal's 1.96:
from scipy import stats
for df in [2, 5, 10, 20, 30, 60, 120]:
print(f"df={df:3d}: t* = {stats.t.ppf(0.975, df):.3f}")
print(f"normal: z* = {stats.norm.ppf(0.975):.3f}")df= 2: t* = 4.303
df= 5: t* = 2.571
df= 10: t* = 2.228
df= 20: t* = 2.086
df= 30: t* = 2.042
df= 60: t* = 2.000
df=120: t* = 1.980
normal: z* = 1.960
With only 3 observations (df = 2) the critical value is more than twice 1.96. That makes confidence intervals from tiny samples much wider, which is honest: tiny samples carry little information. With 30 or more degrees of freedom, t* is already close to z*.
Simulation: why we need t
Let's take many small samples (n = 5) from a normal population, compute t = (x̄ − μ) / (s / √n) for each, and count how often |t| exceeds 1.96. If t were standard normal, it would happen 5% of the time:
import numpy as np
from scipy import stats
rng = np.random.default_rng(1908)
mu, n, reps = 50, 5, 100_000
samples = rng.normal(mu, 10, size=(reps, n))
means = samples.mean(axis=1)
sds = samples.std(axis=1, ddof=1)
t = (means - mu) / (sds / np.sqrt(n))
print(f"share with |t| > 1.96 : {np.mean(np.abs(t) > 1.96):.4f} (normal would say 0.05)")
crit = stats.t.ppf(0.975, n - 1)
print(f"share with |t| > {crit:.3f}: {np.mean(np.abs(t) > crit):.4f} (t with df=4 says 0.05)")share with |t| > 1.96 : 0.1212 (normal would say 0.05)
share with |t| > 2.776: 0.0498 (t with df=4 says 0.05)
Using the normal critical value would produce about 12% "extreme" results instead of 5%. The t critical value gets it right.
The t-distribution in SciPy
stats.t has the same methods as stats.norm, plus the df argument:
| Need | Code |
|---|---|
| density | stats.t.pdf(x, df) |
| area to the left | stats.t.cdf(x, df) |
| area to the right | stats.t.sf(x, df) |
| critical value (quantile) | stats.t.ppf(q, df) |
from scipy import stats
df = 14
print(f"P(T < -1.5) = {stats.t.cdf(-1.5, df):.4f}")
print(f"P(T > 2.2) = {stats.t.sf(2.2, df):.4f}")
print(f"P(|T| > 2.2) = {2 * stats.t.sf(2.2, df):.4f}")
print(f"90% two-tailed critical value: {stats.t.ppf(0.95, df):.3f}")P(T < -1.5) = 0.0779
P(T > 2.2) = 0.0226
P(|T| > 2.2) = 0.0451
90% two-tailed critical value: 1.761
When to use t instead of z
| Situation | Distribution |
|---|---|
inference about a mean, σ unknown (almost always) |
t with n − 1 df |
inference about a mean, σ known (rare) |
standard normal |
| inference about a proportion (large sample) | standard normal |
The t-procedures assume the population is roughly normal. For small samples this matters; for larger samples (n ≥ 30 or so) the Central Limit Theorem makes them robust unless the data is strongly skewed or has extreme outliers.
Test yourself
How does the t-distribution differ from the standard normal?
- It is skewed to the right
- It has heavier tails
- It has a larger mean
- It is only defined for positive values
A sample has 16 observations. How many degrees of freedom does the t-distribution for its mean have?
- 16
- 15
- 17
- 4
What happens to the t-distribution as the degrees of freedom grow very large?
- Its tails get heavier
- It approaches the standard normal distribution
- Its mean grows
- It becomes uniform