PUBH-311 · Lesson 5 of 12 · 28 min
Hypothesis tests for means
▶ Video coming soon A video version of this lesson is on the way.
A food manufacturer’s workplace wellness committee told the Kestrel Valley local health department that its night-shift workers seemed to have high blood pressure. The committee had measured 16 workers and found a mean systolic pressure of 128 mmHg, compared with a regional mean of 122 mmHg for adults of the same age. “Six points higher,” the committee chair said. “Surely that proves shift work is a problem.” Jonah calculated a p-value of 0.064. The chair asked whether that meant the difference was real or not. Dr. Osei said the honest answer was that 16 workers could not tell them either way, and that the question deserved a better study.
This lesson introduces the logic of hypothesis testing and applies it to means, the most common setting in health research. We cover null and alternative hypotheses, test statistics, p-values, significance levels, the two types of error and statistical power, and then the one-sample, paired and two-sample t-tests, their assumptions and their alternatives. We end with sample size calculations for comparing two means and a careful look at what p-values do and do not tell us.
The logic of a hypothesis test
A hypothesis test asks whether the data are consistent with a specific claim about a population. The structure resembles a criminal trial: the defendant is presumed innocent until the evidence is strong enough to reject that presumption beyond reasonable doubt. In statistics the presumption is the null hypothesis (\(H_0\)), usually a statement of no effect or no difference, such as "the mean blood pressure of night-shift workers equals the regional mean." The alternative hypothesis (\(H_1\) or \(H_A\)) is what we would conclude if the evidence against the null is strong: "the mean differs from the regional mean."
Most alternatives in health research are two-sided: we want to detect a difference in either direction. A one-sided alternative (for example, "the mean is higher") is justified only when a difference in the other direction would be impossible or of no interest, and the choice must be made before seeing the data. Switching to a one-sided test after looking at results halves the p-value and is not legitimate.
Every test follows the same steps:
- State the null and alternative hypotheses and choose a significance level.
- Check that the test’s assumptions are reasonable.
- Calculate a test statistic measuring how far the data are from what the null hypothesis predicts, in standard error units.
- Find the p-value: the probability, if the null hypothesis were true, of obtaining a test statistic at least as extreme as the one observed.
- Draw a conclusion in the context of the question, together with an estimate and confidence interval.
p-values and significance levels
A small p-value means the observed data would be unusual if the null hypothesis were true, which counts as evidence against the null. The significance level \(\alpha\) (alpha) is a threshold chosen in advance, conventionally 0.05. If \(p \le \alpha\), the result is called statistically significant and we reject the null hypothesis; if \(p > \alpha\), we fail to reject it. The phrase "fail to reject" is deliberate. A large p-value does not prove the null hypothesis is true; it means the data are compatible with it, often because the study was too small to detect a real effect.
The 0.05 threshold is a convention, popularized by the statistician Ronald Fisher in the 1920s, not a law of nature. A p-value of 0.049 and one of 0.051 represent almost identical evidence. Increasingly, journals and statisticians recommend reporting the exact p-value with an effect estimate and confidence interval rather than simply declaring results significant or not.
Two kinds of error
Because decisions rest on sample data, they can be wrong in two ways (Table 1). A Type I error is rejecting a true null hypothesis: concluding there is an effect when there is none. Its probability is \(\alpha\). A Type II error is failing to reject a false null hypothesis: missing a real effect. Its probability is \(\beta\) (beta). Power, \(1 - \beta\), is the probability that the test detects an effect of a specified size when it truly exists.
| Decision | Null hypothesis true | Null hypothesis false |
|---|---|---|
| Reject the null | Type I error (probability α) | Correct: real effect detected (power, 1 − β) |
| Fail to reject the null | Correct | Type II error (probability β) |
Power depends on four things: the size of the true effect (bigger effects are easier to detect), the variability of the data (less noise helps), the sample size (more data help) and the significance level (a stricter \(\alpha\) reduces power). Researchers usually aim for power of 0.80 or 0.90. A study with low power is likely to miss real effects, and when an underpowered study does find a significant result, it tends to overestimate the effect size.
The one-sample t-test
The one-sample t-test compares a sample mean with a fixed value \(\mu_0\), such as a population norm or a target. The test statistic is
with \(n - 1\) degrees of freedom. It measures how many standard errors the sample mean lies from the hypothesized value.
Worked problem
Night-shift workers’ blood pressure
Sixteen night-shift workers have mean systolic pressure 128 mmHg with SD 12 mmHg. Test whether their mean differs from the regional mean of 122 mmHg at α = 0.05.
Show solution
- Hypotheses: \(H_0: \mu = 122\); \(H_1: \mu \ne 122\) (two-sided).
- Standard error: \(12/\sqrt{16} = 12/4 = 3.0\) mmHg.
- Test statistic: \(t = (128 - 122)/3.0 = 2.00\), with 15 degrees of freedom.
- The two-sided critical value for 15 df is 2.131. Because 2.00 is less than 2.131, the result is not significant at 0.05. Software gives p = 0.064.
- 95 percent CI: \(128 \pm 2.131 \times 3.0 = 121.6\) to \(134.4\) mmHg. The interval includes 122.
Answer: Not statistically significant (t = 2.00, df = 15, p = 0.064). The data are compatible with a true mean anywhere from about 122 to 134 mmHg: anything from no difference to a clinically important one. The study is too small to settle the question.
Note the link between the test and the confidence interval: a two-sided test at \(\alpha = 0.05\) rejects \(H_0\) exactly when the 95 percent CI excludes the hypothesized value. The interval carries more information, because it shows the range of effects consistent with the data.
The paired t-test
Many health studies measure the same people twice, before and after an intervention, or match each person in one group with a similar person in another. Such paired data are not independent, and analyzing them as two separate groups wastes information. The paired t-test works on the differences within each pair. It is simply a one-sample t-test on the differences, testing whether their mean is zero.
Worked problem
A salt-reduction education program
Eight adults with high blood pressure had systolic pressure measured before and after an eight-week salt-reduction program. Before: 142, 150, 138, 160, 145, 155, 148, 152. After: 136, 147, 137, 151, 144, 146, 145, 149. Did pressure change?
Show solution
- Differences (before − after): 6, 3, 1, 9, 1, 9, 3, 3.
- Mean difference: 35/8 = 4.38 mmHg. SD of differences: 3.25 mmHg.
- Standard error: \(3.25/\sqrt{8} = 1.15\) mmHg.
- Test statistic: \(t = 4.38/1.15 = 3.81\) with 7 df. The critical value is 2.365, so the result is significant; software gives p = 0.007.
- 95 percent CI for the mean difference: \(4.38 \pm 2.365 \times 1.15 = 1.7\) to \(7.1\) mmHg.
Answer: Systolic pressure fell by a mean of 4.4 mmHg (95 percent CI 1.7 to 7.1; p = 0.007). Without a control group, however, part of the fall could reflect regression to the mean, seasonal change or measurement habits, so the design limits causal conclusions.
The paired example also shows regression to the mean: people selected because their first measurement was extreme tend, on average, to have less extreme second measurements, even with no intervention. It is a major reason uncontrolled before-and-after studies overstate effects.
The two-sample t-test
The two-sample (independent samples) t-test compares the means of two separate groups, such as an intervention and a control group. The null hypothesis is that the population means are equal. The test statistic divides the difference in sample means by its standard error:
This version, known as Welch’s t-test, does not assume the two groups have equal variances, and its degrees of freedom are calculated by a formula that software handles. The older pooled (Student’s) version assumes equal variances. Many statisticians now recommend Welch’s test as the default because it performs well whether or not variances are equal.
Worked problem
A workplace physical activity program
Fifty employees were randomly assigned to a walking program and 50 to a control group. After three months, the program group averaged 182 minutes of moderate-to-vigorous activity per week (SD 60) and the control group 155 minutes (SD 55). Is the difference significant?
Show solution
- Difference in means: 182 − 155 = 27 minutes per week.
- Standard error: \(\sqrt{60^2/50 + 55^2/50} = \sqrt{72 + 60.5} = \sqrt{132.5} = 11.5\) minutes.
- Test statistic: \(t = 27/11.5 = 2.35\). Welch degrees of freedom are about 97, so the critical value is about 1.98.
- Since 2.35 is greater than 1.98, the result is significant; p = 0.021.
- 95 percent CI: \(27 \pm 1.98 \times 11.5 = 4.2\) to \(49.8\) minutes per week.
Answer: The program group was more active by 27 minutes per week (95 percent CI 4 to 50; p = 0.021). Because assignment was random, confounding is unlikely to explain the difference. The interval is wide: the true effect could be trivial or large.
Assumptions and alternatives
t-tests assume that observations are independent (or properly paired), that the outcome is numerical, and that the sample means are approximately normally distributed. Thanks to the central limit theorem, the last condition is usually met with moderate samples unless the data are very skewed or contain extreme outliers. With small samples, check histograms or box plots.
When assumptions are doubtful, there are alternatives. Strongly right-skewed outcomes can often be log-transformed before testing; the results then describe ratios of geometric means. Nonparametric or rank-based tests make fewer assumptions about the distribution. The Wilcoxon signed-rank test replaces the paired t-test and the Wilcoxon rank-sum test, also called the Mann-Whitney U test, replaces the two-sample t-test. These tests rank the observations and compare ranks rather than raw values. They are robust to outliers but less powerful when t-test assumptions do hold, and they do not directly estimate a difference in means.
To compare means across three or more groups, use analysis of variance (ANOVA), which tests the null hypothesis that all group means are equal using an F statistic. A significant ANOVA says at least one mean differs; follow-up comparisons, with adjustment for multiple testing, identify which. Running many separate t-tests instead inflates the chance of a Type I error, a problem discussed further in Lesson 6. The nonparametric counterpart of one-way ANOVA is the Kruskal-Wallis test.
| Situation | Parametric test | Rank-based alternative |
|---|---|---|
| One sample vs a fixed value | One-sample t-test | Wilcoxon signed-rank test |
| Paired or matched measurements | Paired t-test | Wilcoxon signed-rank test |
| Two independent groups | Two-sample (Welch) t-test | Wilcoxon rank-sum (Mann-Whitney U) test |
| Three or more independent groups | One-way ANOVA | Kruskal-Wallis test |
Sample size for comparing two means
To plan a trial comparing two means, investigators specify the smallest difference worth detecting \(\Delta\), the standard deviation \(\sigma\), the significance level and the desired power. The approximate number needed in each group is
For \(\alpha = 0.05\) (two-sided) \(z = 1.96\); for 80 percent power \(z = 0.84\); for 90 percent power \(z = 1.28\).
Worked problem
Planning a blood pressure trial
A trial will compare a community pharmacist-led program with usual care. The investigators want 80 percent power to detect a 5 mmHg difference in systolic pressure at α = 0.05, and the SD is about 15 mmHg. How many participants are needed per group? What if 15 percent are expected to drop out?
Show solution
- \((1.96 + 0.84)^2 = 2.80^2 = 7.84\).
- \(n = 2 \times 7.84 \times 15^2 / 5^2 = 2 \times 7.84 \times 225 / 25 = 141.1\), so 142 per group.
- Allowing for 15 percent dropout: 142 / 0.85 = 167.1, so recruit 168 per group.
Answer: About 142 participants per group are needed for analysis, or 168 per group (336 in total) after allowing for dropout. Detecting a difference half as large (2.5 mmHg) would need four times as many.
What a p-value is not
In 2016 the American Statistical Association issued a formal statement on p-values, written by Ronald Wasserstein and Nicole Lazar with a panel of statisticians, in response to widespread misuse. Its six principles are worth knowing. P-values can indicate how incompatible the data are with a specified statistical model. They do not measure the probability that the hypothesis is true, or the probability that the data were produced by chance alone. Scientific conclusions and policy decisions should not be based only on whether a p-value passes a threshold. Proper inference requires full reporting and transparency. A p-value does not measure the size of an effect or the importance of a result. By itself, a p-value does not provide a good measure of evidence regarding a model or hypothesis.
Two practical consequences follow. First, distinguish statistical significance from practical or clinical significance. With 50,000 participants, a blood pressure difference of 0.5 mmHg can be highly significant yet unimportant for health. With 16 participants, a 6 mmHg difference can be non-significant yet potentially important. Second, always report the effect estimate with its confidence interval. The interval shows both the direction and the plausible size of the effect, which the p-value alone cannot.
Back to the night shift
Dr. Osei’s reply to the wellness committee explained that the small study had not found a statistically significant difference, but that its confidence interval was consistent with an increase of up to 12 mmHg, which would matter a great deal. She recommended a larger comparison of day and night workers, sized for 80 percent power to detect a 5 mmHg difference, and suggested measuring blood pressure at the start of shifts to avoid differences in timing. The chair agreed it was better than claiming proof from 16 people.
Common mistakes
MistakeInterpreting p = 0.03 as a 3 percent chance that the null hypothesis is true.
InsteadThe p-value is the probability of data at least this extreme if the null were true; it is not the probability of the hypothesis.
MistakeConcluding "no effect" because p > 0.05.
InsteadA non-significant result means the data are compatible with no effect; check the CI and power before drawing conclusions.
MistakeAnalyzing before-and-after measurements with a two-sample t-test.
InsteadUse a paired t-test (or signed-rank test) on the within-person differences.
MistakeChoosing a one-sided test after seeing which direction the data went.
InsteadDecide on one- or two-sided alternatives before data collection; two-sided is the usual default.
MistakeRunning many t-tests to compare several groups.
InsteadUse ANOVA and adjusted follow-up comparisons to control the Type I error rate.
Summary and key terms
- A hypothesis test weighs evidence against a null hypothesis; the p-value is the probability of results at least as extreme if the null were true.
- If p ≤ α the result is statistically significant; failing to reject the null does not prove it.
- Type I error (α) is a false positive; Type II error (β) is a false negative; power (1 − β) rises with effect size, sample size and lower variability.
- The one-sample t-test compares a mean with a fixed value; the paired t-test analyses within-pair differences; Welch’s two-sample t-test compares independent groups.
- Rank-based tests (signed-rank, rank-sum, Kruskal-Wallis) and transformations are alternatives when assumptions fail; ANOVA compares three or more means.
- Sample size for comparing means depends on the difference to detect, the SD, α and power.
- Report effect estimates and confidence intervals; statistical significance is not the same as practical importance.
- Null hypothesis
- The hypothesis of no effect or no difference that a test assesses.
- p-value
- The probability, if the null hypothesis were true, of a test statistic at least as extreme as the one observed.
- Significance level
- The threshold α, chosen in advance, below which a p-value leads to rejecting the null.
- Type I error
- Rejecting a null hypothesis that is true.
- Type II error
- Failing to reject a null hypothesis that is false.
- Power
- The probability of detecting a specified true effect; 1 − β.
- Paired t-test
- A test of whether the mean of within-pair differences is zero.
- Welch’s t-test
- A two-sample t-test that does not assume equal variances.
- Mann-Whitney U test
- A rank-based test comparing two independent groups; also called the Wilcoxon rank-sum test.
- Regression to the mean
- The tendency for extreme first measurements to be followed by less extreme ones.
Practice problems
Work each problem on paper first, then reveal the answer to check.
A sample of 36 children has mean blood lead of 2.4 µg/dL with SD 1.2. Test whether the mean differs from a reference value of 2.0 (critical t for 35 df ≈ 2.03).
Show answer
SE = 1.2/6 = 0.20; t = 0.4/0.20 = 2.00, which is less than 2.03, so not significant at 0.05 (p ≈ 0.053). 95 percent CI: 2.4 ± 2.03 × 0.2 = 1.99 to 2.81.
A study reports p = 0.20 and a 95 percent CI for the difference in mean weight loss of −0.5 to 4.5 kg. What can you conclude?
Show answer
No statistically significant difference, but the data are compatible with anything from a small gain to a 4.5 kg loss; the study is inconclusive rather than showing no effect.
Which test would you use to compare length of hospital stay (strongly skewed) between two hospitals with 20 patients each?
Show answer
The Wilcoxon rank-sum (Mann-Whitney U) test, or a t-test on log-transformed stays.
How many people per group are needed to detect a 4-unit difference in a depression score with SD 10, α = 0.05 and 90 percent power?
Show answer
n = 2 × (1.96 + 1.28)² × 100/16 = 2 × 10.50 × 6.25 = 131.2, so 132 per group.
Lesson quiz · 5 questions
Score 60% or more to complete this lesson.
Create a free account to save your progress, take quizzes and earn a certificate.