Statistics Chapter 10 of 15

Chapter 10: Hypothesis Testing

p-values, errors, power, and honest conclusions

All chapters
On this page
What you will be able to do after this chapter
  • State null and alternative hypotheses correctly, and explain the logic of a test of significance.
  • Define a p-value, interpret it correctly, and avoid the common misinterpretations.
  • Carry out a one-proportion z test and a one-sample t test, including conditions, test statistic, p-value, decision, and a conclusion in context.
  • Explain the relationship between confidence intervals and two-sided tests.
  • Define Type I and Type II errors, significance level, and power, and describe what increases power.
  • Distinguish statistical significance from practical importance, and explain how multiple testing and p-hacking produce false findings.

A confidence interval answers "what values of the parameter are plausible?" A test of significance answers a sharper question: "is this particular claim about the parameter consistent with the data?" Is the new drug better than the old one? Has the graduation rate really changed? Is the coin fair? A test measures how surprising the data would be if a stated claim were true, and if the data would be very surprising, we conclude the claim is doubtful.

10.1

The logic of a hypothesis test

The reasoning is a probabilistic version of proof by contradiction, and is close to a courtroom trial. A defendant is presumed innocent. The prosecution presents evidence. If the evidence would be very unlikely were the defendant innocent, the jury rejects the presumption. If the evidence is not that surprising, the jury does not convict; but "not guilty" is not the same as "proven innocent."

Hypotheses
  • The null hypothesis \(H_0\) is the default claim, the "no effect, no difference, nothing unusual" statement. It always specifies a single value of the parameter: \(H_0\!: p = 0.5\), \(H_0\!: \mu = 100\).
  • The alternative hypothesis \(H_a\) is what we suspect or want evidence for. It is two-sided (\(\ne\)) if we care about a difference in either direction, or one-sided (\(\gt\) or \(\lt\)) if only one direction matters, decided before seeing the data.

Hypotheses are always statements about parameters (\(\mu\), \(p\)), never about statistics (\(\bar{x}\), \(\hat{p}\)): we know the statistic exactly; the question is what it tells us about the population.

The four steps of a test
  1. State the hypotheses and the significance level \(\alpha\) in the context of the problem.
  2. Plan: choose the procedure and check the conditions.
  3. Do: compute the test statistic and the p-value.
  4. Conclude: compare the p-value with \(\alpha\), and state the conclusion in the context of the problem, in terms of evidence for \(H_a\).
10.2

Test statistics, p-values, and decisions

A test statistic measures how far the sample result is from what \(H_0\) predicts, in standard error units:

\[\text{test statistic} = \frac{\text{estimate} - \text{null value}}{\text{standard error (computed assuming } H_0 \text{ is true)}}.\]
The p-value

The p-value is the probability, computed assuming \(H_0\) is true, of getting a test statistic at least as extreme as the one observed (in the direction(s) of \(H_a\)). Small p-values mean that the data would be surprising if \(H_0\) were true, so they are evidence against \(H_0\).

  • Right-tailed (\(H_a\!: \gt\)): p-value = area to the right of the test statistic.
  • Left-tailed (\(H_a\!: \lt\)): area to the left.
  • Two-sided (\(H_a\!: \ne\)): area in both tails beyond \(\pm |\text{statistic}|\), which is twice the one-tail area.
Decision rule and the significance level

Before collecting data choose a significance level \(\alpha\) (commonly 0.05; sometimes 0.10 or 0.01), the probability of a false alarm we are willing to tolerate.

  • If p-value \(\le \alpha\): reject \(H_0\). The result is statistically significant at level \(\alpha\). There is convincing evidence for \(H_a\).
  • If p-value \(\gt \alpha\): fail to reject \(H_0\). The data do not provide convincing evidence for \(H_a\).

We never "accept" \(H_0\) or "prove" it true: failing to find evidence of a difference is not evidence that there is none. The sample may simply have been too small to detect it.

What a p-value is not
  • It is not the probability that \(H_0\) is true. It is the probability of data this extreme given \(H_0\), not the probability of \(H_0\) given the data. (Compare \(P(A \mid B)\) and \(P(B \mid A)\) in Chapter 5, the reversed conditional.)
  • It is not the probability that the result happened "by chance" or that the finding will replicate.
  • It does not measure the size or importance of an effect. A tiny effect in a huge sample can have a tiny p-value.
  • \(p = 0.049\) and \(p = 0.051\) are practically the same evidence. The 0.05 line is a convention, not a law of nature.
10.3

The one-proportion z test

To test \(H_0\!: p = p_0\), use the null value \(p_0\) (not \(\hat{p}\)) in the standard error, since we are computing what would happen if \(H_0\) were true:

\[z = \frac{\hat{p} - p_0}{\sqrt{\dfrac{p_0(1-p_0)}{n}}}.\]
Conditions
  • Random sample or randomized experiment.
  • Independence: \(n\) is less than 10 percent of the population.
  • Large counts: \(np_0 \ge 10\) and \(n(1-p_0) \ge 10\), checked with the null value \(p_0\) (for a test) rather than \(\hat{p}\) (as for an interval).
Example 10.1: A right-tailed test for a proportion

A school district's graduation rate has been 60 percent for years. A new mentoring program is tried, and in a random sample of \(n = 200\) enrolled students (hypothetical data), 138 graduate. Is there convincing evidence that the program raises the graduation rate? Use \(\alpha = 0.05\).

State. \(H_0\!: p = 0.60\) and \(H_a\!: p \gt 0.60\), where \(p\) is the graduation rate under the program.

Plan. One-proportion z test. Conditions: random sample (given); \(200\) is under 10 percent of all enrolled students; \(np_0 = 120\) and \(n(1-p_0) = 80\) are both at least 10.

Do. \(\hat{p} = 138/200 = 0.69\). \(\text{SE} = \sqrt{0.6(0.4)/200} = 0.03464\). \(z = (0.69 - 0.60)/0.03464 = 2.598\). The p-value is the right-tail area \(P(Z \gt 2.598) = 0.0047\).

Conclude. The p-value 0.0047 is less than 0.05, so we reject \(H_0\). There is convincing evidence that the graduation rate under the mentoring program is greater than 60 percent. (If the true rate were 60 percent, only about 0.5 percent of random samples this size would give a sample rate as high as 69 percent.) Because the study was observational, we cannot conclude the program caused the higher rate.

Example 10.2: A two-sided test that fails to reject

In a random sample of 250 shoppers (hypothetical data), 136 say they prefer brand A to brand B. Is there evidence that the preference among all shoppers differs from an even split? Use \(\alpha = 0.05\).

\(H_0\!: p = 0.5\), \(H_a\!: p \ne 0.5\). \(\hat{p} = 136/250 = 0.544\); \(\text{SE} = \sqrt{0.25/250} = 0.03162\); \(z = 0.044/0.03162 = 1.391\). Two-sided p-value \(= 2P(Z \gt 1.391) = 0.164\).

Since \(0.164 \gt 0.05\), we fail to reject \(H_0\). The data do not provide convincing evidence that shoppers' preference differs from 50/50. Notice the wording: we have not shown that preferences are equal; a sample of 250 simply cannot distinguish 54.4 percent from 50 percent with confidence. (The 95 percent confidence interval, \(0.482\) to \(0.606\), contains 0.5 and shows all the values still plausible.)

10.4

The one-sample t test

To test \(H_0\!: \mu = \mu_0\), standardize the sample mean. Because \(\sigma\) is unknown, we use \(s\) and the t distribution with \(n-1\) degrees of freedom:

\[t = \frac{\bar{x} - \mu_0}{s/\sqrt{n}}, \qquad \text{df} = n - 1.\]

Conditions are those of the t interval (Chapter 9): random sample, independence, and an approximately normal population or a large sample. Always graph the data first.

Example 10.3: Testing a mean

A manufacturer's specification says the mean battery life of a tablet model is 7.0 hours. An independent tester measures 10 randomly chosen tablets (the synthetic data of Chapter 9): 7.2, 8.1, 6.9, 7.8, 8.4, 7.5, 6.6, 8.0, 7.7, 7.1. Is there evidence that the true mean differs from 7.0 hours? Use \(\alpha = 0.05\).

State. \(H_0\!: \mu = 7.0\), \(H_a\!: \mu \ne 7.0\).

Plan. One-sample t test. Random sample of 10 tablets; the dotplot shows no outliers or strong skew.

Do. \(\bar{x} = 7.53\), \(s = 0.5736\), \(\text{SE} = 0.1814\). \(t = (7.53 - 7.0)/0.1814 = 2.922\) with \(\text{df} = 9\). Two-sided p-value \(= 2P(t_9 \gt 2.922) = 0.0170\).

Conclude. Since \(0.017 \lt 0.05\), we reject \(H_0\). There is convincing evidence that the mean battery life differs from 7.0 hours; the sample suggests it is higher.

Confidence intervals and two-sided tests agree

A two-sided test of \(H_0\!: \mu = \mu_0\) at level \(\alpha\) rejects exactly when \(\mu_0\) lies outside the \((1-\alpha)\) confidence interval. In Example 10.3 the 95 percent interval is \((7.12,\ 7.94)\), which does not contain 7.0, agreeing with the rejection at \(\alpha = 0.05\). The interval is more informative: it tells us which values are plausible, not just that one value is not.

One-sided or two-sided?

Choose the alternative from the research question, before looking at the data. If a difference in either direction would matter, use two-sided. Switching to a one-sided test after seeing which way the data point cuts the p-value in half and is not honest. When in doubt, use two-sided. For a symmetric test statistic the two-sided p-value is twice the one-sided p-value (when the data lean in the direction of \(H_a\)).

10.5

Errors and power

A test can go wrong in two ways.

\(H_0\) is actually true\(H_0\) is actually false
Reject \(H_0\)Type I error (false positive), probability \(\alpha\)Correct decision, probability power \(= 1 - \beta\)
Fail to reject \(H_0\)Correct decision, probability \(1 - \alpha\)Type II error (false negative), probability \(\beta\)
  • The significance level \(\alpha\) is the probability of a Type I error when \(H_0\) is true; we control it by choosing \(\alpha\).
  • The probability of a Type II error, \(\beta\), depends on the true value of the parameter: it is large when the truth is close to the null value.
  • The power of a test against a specific alternative is the probability of correctly rejecting \(H_0\) when that alternative is true: \(1 - \beta\). Power is the probability of detecting a real effect of a given size.
What increases power?
  • Larger sample size (smaller standard error): the most practical way.
  • Larger effect: the true parameter is farther from the null value.
  • Larger \(\alpha\): easier to reject, but more Type I errors. There is a trade-off: lowering \(\alpha\) raises \(\beta\) for a fixed \(n\).
  • Smaller variability \(\sigma\) in the data (better measurement, more homogeneous sample).
  • A one-sided test (when justified) has more power in its direction than a two-sided one.
Example 10.4: Computing power

Test \(H_0\!: \mu = 100\) against \(H_a\!: \mu \ne 100\) at \(\alpha = 0.05\) with \(n = 36\) and known \(\sigma = 15\). Then \(\text{SE} = 15/6 = 2.5\). The test rejects when \(|\bar{x} - 100| \gt 1.96 \times 2.5 = 4.9\), that is, when \(\bar{x} \lt 95.1\) or \(\bar{x} \gt 104.9\).

Suppose the truth is \(\mu = 106\). Then \(\bar{x} \sim N(106, 2.5)\), and

\[\text{power} = P(\bar{x} \gt 104.9) + P(\bar{x} \lt 95.1) = P\!\left(Z \gt \frac{104.9 - 106}{2.5}\right) + \text{(negligible)} = P(Z \gt -0.44) = 0.670.\]

So the test detects a shift of 6 units about 67 percent of the time, and misses it \(\beta = 0.33\) of the time. For a smaller shift, \(\mu = 104\), the power falls to only 0.36. To reach 80 percent power for a shift of 6, we need about \(n = \left((1.96 + 0.842)\times 15/6\right)^2 = 49.1\), so \(n = 50\).

Underpowered studies

A study with low power will usually fail to reject even when a real effect exists, and the significant results it does produce tend to overestimate the effect (only exaggerated estimates cross the threshold). Plan the sample size in advance, using the power calculation or the tool above.

10.6

Statistical significance versus practical importance

The test statistic is (estimate minus null) divided by standard error. With a huge sample the standard error is tiny, so even a trivial difference produces a large statistic and a tiny p-value. Statistical significance answers "is there evidence of any difference?", not "is the difference large enough to matter?"

Example 10.5: Significant but not important

A tutoring app is tested on \(n = 10{,}000\) students (hypothetical). Test scores nationally have mean 100 and SD 15. The app group has \(\bar{x} = 100.5\) and \(s = 15\). Then \(\text{SE} = 15/\sqrt{10000} = 0.15\), \(t \approx 0.5/0.15 = 3.33\), and the two-sided p-value is about 0.0009: highly significant. But the 95 percent interval is \(100.5 \pm 0.29\), that is, \((100.2,\ 100.8)\), and an average gain of half a point on a scale whose standard deviation is 15 is only 0.03 standard deviations, almost certainly of no practical value. Always report the effect size and a confidence interval alongside the p-value, and judge the size against the context.

The opposite mistake is just as common: a non-significant result in a small study does not show that the effect is zero. The confidence interval will typically be wide, including both "no effect" and "a large effect."

10.7

Multiple testing and p-hacking

If \(H_0\) is true and \(\alpha = 0.05\), each test has a 5 percent chance of a false alarm. Run 20 independent tests of true null hypotheses and the chance of at least one false alarm is \(1 - 0.95^{20} = 0.64\). Search enough subgroups, outcome measures, or model specifications and something will "come out significant" by luck alone. P-hacking (also called data dredging or the garden of forking paths) is this practice, deliberate or not: trying many analyses and reporting only those that cross \(p \lt 0.05\).

Protecting yourself
  • Decide on the hypotheses, outcomes, and analysis plan before looking at the data (pre-registration).
  • Report all tests you ran, not only the significant ones.
  • When many tests are unavoidable, adjust: the Bonferroni correction uses \(\alpha/k\) for each of \(k\) tests, guaranteeing the chance of even one false positive stays at most \(\alpha\). (For \(k = 20\) tests, use \(0.05/20 = 0.0025\) for each.)
  • Treat exploratory findings as hypotheses to be confirmed on new data.
  • Prefer effect sizes and interval estimates to pass/fail verdicts.
Going deeper: The ASA statement on p-values, and the base rate of true hypotheses

In 2016 the American Statistical Association issued a statement on p-values with six principles: (1) p-values can indicate how incompatible the data are with a specified statistical model; (2) they do not measure the probability that the studied hypothesis is true, or the probability that the data were produced by random chance alone; (3) scientific conclusions and policy decisions should not be based only on whether a p-value passes a specific threshold; (4) proper inference requires full reporting and transparency; (5) a p-value, or statistical significance, does not measure the size of an effect or the importance of a result; and (6) by itself, a p-value does not provide a good measure of evidence regarding a model or hypothesis.

Why is a "significant" result often less reliable than \(1 - \alpha\) suggests? Consider 1,000 hypotheses tested, of which only 100 are truly non-null (a base rate of 10 percent), using \(\alpha = 0.05\) and power 0.80. The tests detect \(0.80 \times 100 = 80\) real effects, but also produce \(0.05 \times 900 = 45\) false positives. Of the 125 significant results, 45, or 36 percent, are false. This is the same base-rate logic as the disease screening example of Chapter 5, and it is part of the explanation for the replication crisis in several sciences. The false-positive share of significant results depends on power and on how plausible the hypotheses were to begin with, not only on \(\alpha\).

10.8

Chapter summary

Key ideas and formulas
  • \(H_0\) (a single value, the default claim) versus \(H_a\) (one-sided or two-sided, chosen before the data). Hypotheses are about parameters.
  • Test statistic \(= (\text{estimate} - \text{null value})/\text{SE}\), with the SE computed under \(H_0\).
  • P-value = probability, if \(H_0\) is true, of a statistic at least as extreme as observed. Small p-value: evidence against \(H_0\). It is not the probability \(H_0\) is true.
  • If p-value \(\le \alpha\): reject \(H_0\); otherwise fail to reject. Never "accept" \(H_0\). Conclude in context.
  • One proportion: \(z = (\hat{p} - p_0)/\sqrt{p_0(1-p_0)/n}\). One mean: \(t = (\bar{x} - \mu_0)/(s/\sqrt{n})\) with \(\text{df} = n-1\).
  • A two-sided test at level \(\alpha\) rejects \(\mu_0\) exactly when it lies outside the \((1-\alpha)\) confidence interval.
  • Type I error (reject a true \(H_0\)), probability \(\alpha\); Type II error (miss a real effect), probability \(\beta\); power \(= 1 - \beta\). Power rises with \(n\), effect size, \(\alpha\), and lower variability.
  • Statistical significance is not practical importance: report effect sizes and intervals.
  • Multiple tests inflate false positives: \(1 - (1-\alpha)^k\). Pre-register, report everything, and adjust (Bonferroni).

Key terms

TermMeaning
Null hypothesis \(H_0\)The default claim, specifying one value of the parameter
Alternative \(H_a\)The claim we seek evidence for, one-sided or two-sided
Test statisticStandardized distance between the estimate and the null value
P-valueProbability of a result at least as extreme, assuming \(H_0\) is true
Significance level \(\alpha\)Chosen threshold; also the Type I error probability
Type I / Type II errorRejecting a true \(H_0\) / failing to reject a false \(H_0\)
PowerProbability of rejecting \(H_0\) when a specific alternative is true
P-hackingTrying many analyses and reporting only the significant ones
10.9

Practice