The T-Test › The Student's T-Distribution

Michael BrenndoerferJanuary 3, 20264 min read
Machine Learning from ScratchAll chapters
Part 2 of 9Hypothesis Testing
Chapter 15The T-Test › The Student's T-Distribution
Reading section 3 of 11 · The Student's T-Distribution · 4 minSection 3 of 11 · 4 min

Book contents

Section 3 of 11 · 4 min read

The T-Test › The Student's T-DistributionOne section · Sections in this chapter3 / 11 ↓
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

Mathematical Foundation

When we replace σ\sigma with ss, the test statistic becomes:

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

This ratio follows a t-distribution with n−1n - 1 degrees of freedom (df). The degrees of freedom represent the amount of independent information available to estimate the variance. When computing ss from nn observations, we use up one degree of freedom estimating the mean, leaving n−1n - 1 degrees of freedom for estimating variance.

The t-distribution has several key properties:

  1. Bell-shaped and symmetric: Like the normal distribution, centered at zero under the null hypothesis
  2. Heavier tails: More probability in the extreme values than the normal distribution
  3. Parameterized by degrees of freedom: The shape depends on df, with smaller df meaning heavier tails
  4. Converges to normal: As df→∞df \to \infty, the t-distribution approaches the standard normal

The heavier tails account for the uncertainty added by estimating variance: with small samples, ss can deviate substantially from σ\sigma, so extreme t-values become more probable. The t-distribution therefore requires larger critical values to reject the null hypothesis.

Why Heavier Tails Make Sense

Consider what happens when ss happens to underestimate σ\sigma:

  • The denominator s/ns/\sqrt{n} is too small
  • The t-statistic is inflated
  • We might incorrectly reject H0H_0

When ss overestimates σ\sigma:

  • The denominator is too large
  • The t-statistic is deflated
  • We might miss a real effect

These errors don't favor either direction on average, but they add variability. The t-distribution captures exactly this additional spread. With only 5 observations (df = 4), the sample standard deviation is quite unreliable, so the t-distribution has very heavy tails. With 100 observations (df = 99), ss is a much more reliable estimate of σ\sigma, and the t-distribution is nearly identical to the normal.

Out[2]:
Visualization
Comparison of t-distributions with different degrees of freedom to the standard normal distribution.
The t-distribution compared to the standard normal. With few degrees of freedom, the t-distribution has substantially heavier tails, meaning extreme values are more likely. As degrees of freedom increase, the t-distribution converges to the normal distribution.

Critical Values: The Practical Impact

The heavier tails translate directly into larger critical values. For a two-sided test at α=0.05\alpha = 0.05:

Degrees of Freedomt-criticalz-critical
52.5711.960
102.2281.960
202.0861.960
302.0421.960
1001.9841.960
∞\infty1.9601.960

With df = 5, you need a t-statistic 31% larger than the z-critical value to reject H0H_0. This penalty appropriately reflects the unreliability of variance estimates from small samples. By df = 30, the difference is only about 4%, which is why older textbooks sometimes said "use z for n > 30." Modern practice uses the t-distribution regardless, as computational tools make it trivially easy.

Out[3]:
Visualization
Plot showing t-critical values decreasing toward z-critical value as degrees of freedom increase.
Critical values for two-sided tests at alpha = 0.05. The t-critical values decrease toward the z-critical value (1.96) as degrees of freedom increase.