Paired t-test for before-and-after measurements
Match two measurements by participant ID and work through eight fictional pairs. See how mispairing can change the standard error even when the mean difference stays the same.
AcademicFix Editorial Team · Sources checked
Bu rehberi Türkçe okuyun- Mean difference
- +2.50 points
- Correctly matched SE
- 0.87 points
- Incorrectly matched SE
- 3.25 points
Fictional example. Rearranging the follow-up scores leaves the column means unchanged. It changes the differences assigned to individuals and how widely those differences vary.
Compare the pairingsSuppose you merge baseline and follow-up scores for eight people. If the files are in different orders and you match by row number, the average increase can still look right. In the fictional example below, it stays at 2.50 points, while the standard error rises from 0.87 to 3.25. For a paired t-test, match the measurements by participant ID and compute follow-up − baseline within each pair. The test uses the mean and variability of those differences. NIST on paired observations · CUNY on paired data
Use this guide when you have two quantitative measurements from the same units or pairs defined by your study design. It covers a two-sided analysis of the mean difference.
On this page
Match each measurement to its participant or pair
Join the two measurement files by participant ID or by the pair code established in the design. Two observations from the same participant form one pair. Matching people from separate groups by row number does not create a valid pair. For two independent groups, see the Welch t-test guide. NIST on the definition of a pair · CUNY on paired samples
Check that each ID has one baseline and one follow-up value. List duplicate IDs and missing measurements separately. In the standard calculation, n is the number of complete pairs. With paired vectors, R omits the entire pair when either value is missing. Report both the number of complete pairs and how many were excluded. R stats on complete pairs · CUNY on computing within-pair differences
Check the distribution of differences and the independence of pairs
The standard paired t-test assumes independence across pairs. For the classical small-sample calculation, the normal model applies to the within-pair differences. The two raw score columns can have different variances. CUNY on the model and assumptions · NIST Technical Note 2106 on the paired calculation
Plot the differences on a dot plot or a Q–Q plot. With few pairs, look for strong skew or an observation that drives the result. For an unusual difference, check the ID and the original measurements. If participants contribute more than two observations or the pairs are dependent, choose an analysis that reflects the design. CUNY’s Q–Q plot of the differences · NIST Technical Note 2106, sections 3.1.1.4 and 4.2.2
Recalculate the 2.50-point difference from eight pairs
Fictional example. Eight people have scores on the same scale before and after an activity. The last column deliberately swaps the follow-up scores for IDs 1 and 2, 3 and 4, 5 and 6, and 7 and 8.
| ID | Before | After | Diff. | Wrong diff. |
|---|---|---|---|---|
| 1 | 48 | 50 | 2 | 15 |
| 2 | 59 | 63 | 4 | −9 |
| 3 | 65 | 64 | −1 | 12 |
| 4 | 71 | 77 | 6 | −7 |
| 5 | 77 | 77 | 0 | 9 |
| 6 | 83 | 86 | 3 | −6 |
| 7 | 90 | 95 | 5 | 5 |
| 8 | 94 | 95 | 1 | 1 |
The correctly matched differences sum to 20. Their mean is 2.50 points, and their sample standard deviation is 2.45 points. Divide that standard deviation by √8 to get a standard error of about 0.87 points. For a hypothesized mean difference of zero, divide 2.50 by the unrounded standard error to get t = 2.89. There are 8 − 1 = 7 degrees of freedom. For the two-sided 95% confidence interval, add and subtract the critical t value times the standard error from the estimate. NIST Technical Note 2106, section 3.1.2.3 · CUNY on the test and interval
The swapped differences still sum to 20 because both columns contain the same scores as before. Their standard deviation rises to 9.20 and their calculated standard error to 3.25 in this example. The last column illustrates a linkage error. Use the original IDs to recover the within-person differences before drawing conclusions.
Reproduce it in R. Verify the order by ID before passing the vectors. Both calls below test the same eight differences. R stats, paired t-test implementation
before <- c(48, 59, 65, 71, 77, 83, 90, 94)
after <- c(50, 63, 64, 77, 77, 86, 95, 95)
t.test(after, before, paired = TRUE)
t.test(after - before)Report the mean change with its uncertainty
Fictional results sentence. Across eight complete pairs, the mean follow-up minus baseline difference was 2.50 points (95% CI [0.45, 4.55], t(7) = 2.89, two-sided p = 0.0234).
With one group measured before and after an intervention, outside events, natural changes over time, or practice with the test can also explain the change. Report the observed mean change and look to the comparison design to assess the intervention’s effect. Cochrane Handbook, section 25.5 · Campbell and Stanley, Design 2
Use the guide to p-values, effect sizes, and confidence intervals to judge the interval against differences that would matter for your study. If participants were selected for unusually high or low starting scores, see the worked example of regression to the mean.
Record four decisions before closing the data file
- Write down the unit of observation and the ID used to form pairs.
- Record the subtraction direction, number of complete pairs, and missing measurements.
- Keep the plot of the differences, notes on possible data errors, and the basis for assuming independence across pairs.
- Report the mean difference, confidence interval, and what the design allows you to conclude.
Sources
- NIST/SEMATECH · Analysis of paired observations
- NIST Technical Note 2106 · Paired t-test and confidence interval
- Mikael Vejdemo-Johansson, CUNY · Two-sample Inference: Paired Data
- R Core · stats::t.test source
- Cochrane Handbook · Risk of bias in uncontrolled before–after studies
- Campbell and Stanley (1963) · The One-Group Pretest-Posttest Design