The t-test & Comparing Two Groups
Statistical Inference & Applied Statistics
Chapter 5 · The t-test & Comparing Two Groups
Every z-test in Chapter 4 quietly assumed the population standard deviation, σ, was already known. In real work, that's almost never true — only the sample standard deviation s is available, computed exactly the way Probability & Statistics Fundamentals' own Chapter 9 defined it, with Bessel's n−1 correction. That single substitution changes the math more than it might seem.
Why Estimating σ Changes the Distribution
When σ is estimated from the same limited sample as s, the resulting test statistic carries extra uncertainty on top of ordinary sampling error — and its true sampling distribution is no longer exactly normal. It follows the t-distribution instead: shaped like the normal bell curve, but with heavier tails, reflecting that extra layer of uncertainty from estimating s itself.
df = n − 1 — exactly the denominator of the sample variance formula, Probability & Statistics Fundamentals Chapter 9's own Bessel's correction, reused here as the t-distribution's own shape parameter.
df (and therefore n) grows, the t-distribution's tails thin out and it converges toward the standard normal — the extra uncertainty from estimating s matters less and less with more data, exactly the CLT's own "more data, more predictable" pattern from Chapter 8 of the sibling course, now applied to the act of estimating σ itself.
The One-Sample t-test
t = (x̄ − μ₀) / (s/√n) — identical in shape to Chapter 4's z-statistic, but built from the sample standard deviation s, and compared against a t-distribution with df = n − 1, not the standard normal.
Worked example: a team doesn't know the true σ, only their sample — n = 25, x̄ = 204ms, s = 32ms. Testing H₀: μ = 200:
| Quantity | Value |
|---|---|
| SE = s/√n | 32/5 = 6.4ms |
| t | (204−200)/6.4 = 0.625 |
| df | 25 − 1 = 24 |
| Critical value (two-tailed, α=0.05, df=24) | 2.064 |
| Decision | |0.625| < 2.064 → fail to reject H₀ |
Same conclusion as Chapter 4's own z-test on similar numbers — unsurprising, since a t-distribution with 24 degrees of freedom is already close to normal.
Comparing Two Groups: The Two-Sample t-test
Comparing two independent groups' means — exactly the shape of an A/B test — uses Welch's t-test, which doesn't assume the two groups share the same variance (a more honest default than assuming equal variances, and the version most statistical software now uses by default):
t = (x̄₁ − x̄₂) / √(s₁²/n₁ + s₂²/n₂)
df = min(n₁, n₂) − 1, which tends to slightly understate the true df and therefore errs toward being more cautious about rejecting H₀ — a reasonable simplification for this course's own scope.
Worked example: Group A (control), n₁=20, x̄₁=205ms, s₁=25ms; Group B (treatment), n₂=22, x̄₂=190ms, s₂=28ms.
| Quantity | Value |
|---|---|
| SE_diff = √(25²/20 + 28²/22) | ≈ 8.178 |
| t = (205−190)/8.178 | ≈ 1.834 |
| df = min(20,22) − 1 | 19 |
| Critical value (two-tailed, α=0.05, df=19) | 2.093 |
| Decision | |1.834| < 2.093 → fail to reject H₀ |
The t-test in Code
Hands-On Exercises
Testing H₀: μ = 50, a sample of n = 16 gives x̄ = 54, s = 10. Compute the standard error, the t-statistic, and the degrees of freedom. Using the critical value 2.131 (two-tailed, α=0.05, df=15), state the decision.
Group 1: n₁=15, x̄₁=48, s₁=6. Group 2: n₂=18, x̄₂=53, s₂=7. Compute Welch's t-statistic, the conservative degrees of freedom, and using the critical value 2.145 (two-tailed, α=0.05, df=14), state the decision.
Explain, in your own words, why the t-distribution needs heavier tails than the normal distribution when σ is unknown and estimated by s, and why a small-sample t-test's critical value (like 2.262 at df=9) is noticeably larger than the z-test's fixed 1.96. Then explain why that gap shrinks as sample size grows.
Chapter 5 Quick Reference
- When
σis unknown and estimated by samples, use the t-distribution — heavier tails than normal, reflecting the extra uncertainty from estimatingsitself - Degrees of freedom (one-sample):
df = n − 1— the exact same denominator as Chapter 9's own Bessel's correction - One-sample t:
t = (x̄ − μ₀)/(s/√n)— same shape as the z-statistic, compared against a t-distribution instead - Welch's two-sample t:
t = (x̄₁−x̄₂)/√(s₁²/n₁ + s₂²/n₂), with a conservativedf = min(n₁,n₂)−1 - The t-distribution converges to the normal distribution as
n(and therefore df) grows - A visible descriptive difference between two groups doesn't automatically mean a statistically significant one — Chapter 6's own A/B testing chapter builds directly on this
- Next chapter: A/B testing in practice