James's Math Hub
Statistics & Probability

Lesson 12 / 13 · 14 min read

Hypothesis Testing

Null vs alternative, test statistics, p-values, and the two ways to be wrong.

The logic

A hypothesis test asks: is the effect I'm seeing real, or could plain chance explain it? We start by assuming nothing is going on, then check whether the data is too surprising for that assumption to survive.

Null and alternative hypotheses

  • Null hypothesis H0H_0: no effect, no difference — the status quo. For example μ=100\mu = 100.
  • Alternative hypothesis HaH_a: the claim we're testing. For example μ100\mu \neq 100 (two-sided) or μ>100\mu > 100 (one-sided).

We never "prove" H0H_0. We either reject it or fail to reject it.

The test statistic

For a mean, the test statistic counts how many standard errors xˉ\bar{x} sits from the null value μ0\mu_0:

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

The p-value

The p-value is the probability — assuming H0H_0 is true — of getting a result at least as extreme as the one observed.

  • Small p-value → the data would be very unlikely under H0H_0 → evidence against H0H_0.
  • Large p-value → the data is consistent with H0H_0.

Significance level

Choose a threshold α\alpha (often 0.050.05) in advance:

  • If pαp \leq \alpha: reject H0H_0 — the result is "statistically significant."
  • If p>αp > \alpha: fail to reject H0H_0.

Worked example

A factory claims its bottles average μ0=500\mu_0 = 500 ml. A sample of n=64n = 64 bottles gives xˉ=497\bar{x} = 497 with σ=8\sigma = 8. Test Ha:μ500H_a: \mu \neq 500 at α=0.05\alpha = 0.05.

z=4975008/64=31=3z = \frac{497 - 500}{8 / \sqrt{64}} = \frac{-3}{1} = -3

For a two-sided test, the p-value is P(Z>3)0.0027P(|Z| > 3) \approx 0.0027. Since 0.0027<0.050.0027 < 0.05, we reject H0H_0 — the fill amount differs significantly from 500 ml.

Two kinds of error

H0H_0 is trueH0H_0 is false
Reject H0H_0Type I errorcorrect
Fail to rejectcorrectType II error
  • Type I error: rejecting a true null — a false positive. Its probability is α\alpha.
  • Type II error: failing to detect a real effect — a false negative. Its probability is β\beta.
  • Power =1β= 1 - \beta: the chance of catching a real effect. A larger sample raises power.

Significant is not the same as important

With a big enough sample, even a tiny, meaningless difference can come out "statistically significant." Always look at the size of the effect, not just the p-value.

Key takeaways

  • H0H_0 = no effect; HaH_a = the claim. You reject or fail to reject — never prove H0H_0.
  • z=(xˉμ0)/(σ/n)z = (\bar{x} - \mu_0)/(\sigma/\sqrt{n}); the p-value measures how surprising the data is under H0H_0.
  • Reject when pαp \leq \alpha (commonly 0.050.05).
  • Type I = false positive (rate α\alpha); Type II = false negative (rate β\beta); power =1β= 1 - \beta.
  • Statistical significance \neq practical importance.