Paired samples t-test
A paired samples t-test (also called a dependent or repeated-measures t-test) compares two measurements taken on the same cases. Typical designs are pre-test vs post-test, left eye vs right eye, two conditions in a within-subjects experiment, or matched pairs such as twins. Each case acts as its own control, which is the source of the test’s power.
How it works
The test calculates each case’s difference (measurement 1 − measurement 2), then runs a one-sample t-test on those differences against zero:
t = d̄ / (s_d / √n)
where d̄ is the mean difference, s_d the standard deviation of the differences, and n the number of pairs. Degrees of freedom = n − 1.
- H₀: the mean difference in the population is zero (μ_d = 0).
- H₁: the mean difference is not zero (μ_d ≠ 0).
When to use it
- The outcome is continuous.
- Every case has both measurements, and you know which value pairs with which.
- There are exactly two measurements. For three or more, use repeated-measures ANOVA or the Friedman test.
If the two sets of scores come from different people, you need the independent samples t-test instead. Not sure? See which t-test to use.
Assumptions
- Pairs are independent of each other. One participant’s difference doesn’t affect another’s.
- The differences are approximately normal. Only the differences need to be normal, not the two original columns. This matters most with small samples. Strong skew or extreme outliers in the differences point to the Wilcoxon signed-rank test.
Equal variances are not required, because the test only ever looks at one column, the differences.
Worked example: Student’s sleep data
These are the data Student used to introduce the t-test in 1908. Ten patients each took two sleeping drugs on separate occasions, and researchers recorded the hours of extra sleep each drug gave compared with no drug. The data ship with R as sleep.
Step 1: describe
| Mean | SD | |
|---|---|---|
| Drug 1 | 0.75 h | 1.79 |
| Drug 2 | 2.33 h | 2.00 |
| Difference (2 − 1) | 1.58 h | 1.23 |
Drug 2 gave more sleep for 9 of the 10 patients, with one tie. Notice the difference column’s SD (1.23) is smaller than either drug’s SD. Patients vary a lot in how much extra sleep they get, but much less in how the two drugs compare for the same patient.
Step 2: check the assumption
The ten differences give a Shapiro-Wilk p of .033. At the conventional .05 that would count as non-normal. Analytika runs its normality pre-check at α = .01, because normality tests on small samples are unreliable and the t-test tolerates mild departures. So it proceeds with the paired t-test. A cautious analyst could report the Wilcoxon signed-rank test as a sensitivity check. Here it agrees: W = 0, p = .004.
Step 3: run the test
Group 1 (extra_drug1): mean=0.7500, n=10, sd=1.7890 Group 2 (extra_drug2): mean=2.3300, n=10, sd=2.0022 Mean difference: -1.5800 Difference CI (95%): [-2.4599, -0.7001] T-statistic: -4.0621 P-value: 0.002833 Cohen's d: -1.2846 df: 9 95% CI: [-2.1180, -0.4146] Rows excluded for missing values: 0 of 10
> with(sleep, t.test(extra[group == 1], extra[group == 2], paired = TRUE))
Paired t-test
data: extra[group == 1] and extra[group == 2]
t = -4.0621, df = 9, p-value = 0.002833
alternative hypothesis: true mean difference is not equal to 0
95 percent confidence interval:
-2.4598858 -0.7001142
sample estimates:
mean difference
-1.58The results match. Analytika’s test suite checks this case against R to four decimal places. Both calculate drug 1 − drug 2, hence the negative signs.
Step 4: interpret
- p = .003: if the drugs truly had the same average effect, a difference this large would arise in fewer than 1 in 300 studies like this. There’s evidence that drug 2 produces more extra sleep.
- 95% CI for the difference: 0.70 to 2.46 hours, written here as drug 2 minus drug 1. The advantage is plausibly anywhere from about 40 minutes to 2½ hours.
- Cohen’s d = −1.28, 95% CI [−2.12, −0.41]. The mean difference is over one SD of the differences, a large effect. (For paired designs this d is calculated from the differences and is often written d_z.)
Step 5: report it (APA 7)
A paired samples t-test showed that patients gained more extra sleep with drug 2 (M = 2.33, SD = 2.00) than with drug 1 (M = 0.75, SD = 1.79), mean difference = 1.58 hours, 95% CI [0.70, 2.46], t(9) = −4.06, p = .003, d = −1.28.
Why pairing matters: the same data, analysed wrongly
Analyse these 20 numbers as if they came from two separate groups of 10 patients, and an independent (Welch) t-test gives p = .079: no evidence of a difference. Same data, opposite conclusion. The independent test treats the large differences between patients as noise. The paired test removes them by comparing each patient with themselves. Using the right test for the design isn’t a formality. Here it decides the finding.
The mistake can go the other way too. Treating independent groups as paired produces nonsense, because any “pairing” of rows is arbitrary.
Common mistakes
- Running an independent t-test on before/after data, which wastes power, as shown above.
- Checking normality of each column instead of the differences.
- Dropping the pairing during data cleaning. If rows get sorted separately or a participant is missing one measurement, the pairs no longer line up. Pairs with a missing value must be dropped as a pair.
- Claiming the intervention caused the change in a pre/post design with no control group. Time, practice effects and regression to the mean can all produce changes on their own.
How to run it
- SPSS: Analyze → Compare Means → Paired-Samples T Test, then select the two columns as a pair.
- R:
t.test(before, after, paired = TRUE) - Python:
scipy.stats.ttest_rel(before, after) - Analytika: pairs of columns named like
score_pre/score_postorT1anx/T2anxare recognised as paired automatically. Otherwise, ask for a paired t-test by name. Analytika checks the differences and uses the paired t-test, or the Wilcoxon signed-rank test if they’re clearly non-normal.
References
- Cushny, A. R., & Peebles, A. R. (1905). The action of optical isomers: II. Hyoscines. The Journal of Physiology, 32(5–6), 501–510.
- Student. (1908). The probable error of a mean. Biometrika, 6(1), 1–25.
More in Comparing groups
Try it with the free tools
Run this on your own data
Upload a dataset and ask your question in plain English. Analytika checks the assumptions, picks the test, runs it, and writes the results up in APA format.