Confidence Intervals and Test Assumptions › Choosing Between Z-Tests and T-Tests

Michael BrenndoerferUpdated January 12, 20263 min read
Machine Learning from ScratchAll chapters
Part 2 of 9Hypothesis Testing
Chapter 13Confidence Intervals and Test Assumptions › Choosing Between Z-Tests and T-Tests
Reading section 5 of 9 · Choosing Between Z-Tests and T-Tests · 3 minSection 5 of 9 · 3 min

Book contents

Section 5 of 9 · 3 min read

Confidence Intervals and Test Assumptions › Choosing Between Z-Tests and T-TestsOne section · Sections in this chapter5 / 9 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

The choice between z-tests and t-tests depends on whether you know the population standard deviation.

The Z-Test: Known Variance

The z-test assumes you know the population standard deviation σ\sigma:

z=xˉ−μ0σ/nz = \frac{\bar{x} - \mu_0}{\sigma / \sqrt{n}}

Under H0H_0, this follows a standard normal distribution N(0,1)N(0, 1).

When do you know σ\sigma? Rarely. Possible scenarios include:

  • Measurement instruments with known precision from extensive calibration
  • Standardized tests with established population parameters
  • Very large historical datasets that effectively reveal the population

The T-Test: Unknown Variance

The t-test estimates σ\sigma from the sample using ss:

t=xˉ−μ0s/nt = \frac{\bar{x} - \mu_0}{s / \sqrt{n}}

Under H0H_0, this follows a t-distribution with n−1n-1 degrees of freedom.

Why the t-distribution? When you estimate σ\sigma with ss, you introduce additional uncertainty. The sample standard deviation ss is itself a random variable. The t-distribution has heavier tails than the normal to account for this uncertainty.

The T-Distribution: Heavy Tails for Small Samples

Out[10]:
Visualization
Line plot comparing t-distributions with different degrees of freedom to the standard normal distribution.
The t-distribution has heavier tails than the normal distribution, especially for small degrees of freedom. This means extreme values are more likely under the t-distribution, which correctly accounts for the uncertainty from estimating σ with s. As df increases, the t-distribution approaches the normal.

The practical consequence: t-tests give larger p-values (and wider confidence intervals) than z-tests for the same data. This is appropriate because we're less certain when we don't know σ\sigma.

Degrees of Freedomt Critical Value (95% CI)Compared to z = 1.96
52.57131% larger
102.22814% larger
202.0866% larger
302.0424% larger
1001.9841% larger
∞1.960Same as z

For practical purposes, with n > 30, the difference between t and z is usually negligible. But always use the t-test when σ\sigma is unknown. There's no benefit to using z without a known σ\sigma, and it can inflate your Type I error rate for small samples.