Probability & Statistics · p-value

p-value

A p-value is the probability, computed as if the null hypothesis H0 were true, of a result at least as extreme as the one observed. Here a machine should fill bags with 500 g on average; the curve shows where the mean of n bags would land if it did.

p-values in this visualization

A hypothesis test asks whether data would be surprising under a default claim, the null hypothesis H0H_0. Here H0H_0 says that a machine fills bags with μ=500\mu = 500 g on average; bag weights are independent and normal with σ=10\sigma = 10 g, and a study weighs nn bags and takes their mean xˉ\bar x. The p-value is the probability, computed as if H0H_0 were true, of a mean at least as extreme as the observed one, in the direction named by the alternative hypothesis H1H_1. A test at level α=0.05\alpha = 0.05 raises an alarm when p<0.05p < 0.05.

What exactly is p the probability of? Under H0H_0 the mean Xˉ\bar X is normal with mean 500 and standard error 10/n10/\sqrt{n}, so the observed mean sits at z=(xˉ−500)/(10/n)z = (\bar x - 500)/(10/\sqrt{n}). For H1 ⁣:μ<500H_1\!: \mu < 500 the p-value is the area to the left of zz, Φ(z)\Phi(z); for μ>500\mu > 500 it is the area to the right; for μ≠500\mu \neq 500 it is both tails, 2Φ(−∣z∣)2\Phi(-|z|). The reruns show the same thing by counting: on a machine that truly fills 500 g, the share of studies whose mean is at least this extreme settles near p. The direction has to be chosen before the data are seen. Picking the smaller of the two one-sided p-values afterwards raises an alarm 10% of the time when H0H_0 is true, twice the stated rate. With the direction fixed in advance, p is uniformly distributed between 0 and 1 under H0H_0, so the test raises a false alarm exactly a fraction α\alpha of the time.

Why is p not the probability that H0H_0 is true? It is computed entirely inside the world of H0H_0: it is P(a mean at least this extreme∣H0)P(\text{a mean at least this extreme} \mid H_0), not P(H0∣the data)P(H_0 \mid \text{the data}). Turning it around needs two quantities that p never uses: how common short machines are to begin with, and the power, the chance that the test raises an alarm on a short machine. With 25 bags and a 3 g shortfall the power is about Φ(1.5−1.645)\Phi(1.5 - 1.645). In the odds form of Bayes' theorem, an alarm multiplies the odds of short against good by power ÷ α\alpha, about 8.85 here, taking prior odds of 1 : 4 to about 2.2 : 1. After the same alarm, the share of good machines among the alarms is about 2.7% when 80% of machines are short and about 68% when 5% are. These shares use only the fact that an alarm was raised; the value of xˉ\bar x itself says more.

Why can a tiny difference be significant? For a fixed observed shortfall, ∣z∣=∣xˉ−500∣n/σ|z| = |\bar x - 500|\sqrt{n}/\sigma grows with n\sqrt{n}, so the lower-tail p gets smaller as more bags are weighed: four times as many bags doubles ∣z∣|z|. In the lower-tail test, half a gram below 500 is significant at α=0.05\alpha = 0.05 from 1083 bags on. A small p says that the data would be unusual if μ\mu were exactly 500; it does not say that the difference matters. The converse fails too: a real shortfall often raises no alarm, so p>0.05p > 0.05 does not show that the machine is fine. Report the size of the difference with a confidence interval: the two-sided test at α=0.05\alpha = 0.05 rejects μ=500\mu = 500 exactly when the 95% interval xˉ±z∗σ/n\bar x \pm z^*\sigma/\sqrt{n} (z∗≈1.96z^* \approx 1.96) leaves out 500.

Things to notice

  • The bags in the upper layer are example data placed so that their mean is exactly xˉ\bar x; the test uses only xˉ\bar x, nn and σ\sigma.
  • The lower axis always spans six standard errors either side of 500, so the curve keeps its shape; the frame under the upper axis marks that window, and it narrows as nn grows.

Controls

  • Drag on the lower layer to place xˉ\bar x. Moving xˉ\bar x or the direction lever recounts the same reruns; a new nn starts both modes afresh.

Related