Worked statistical example

Paired vs unpaired t test: the same data, two answers.

Student's sleep data contain two measurements from each of ten patients. Treating those columns as independent groups discards the experimental design—and changes the answer.

10 patients2 conditionsExact reference dataset7-minute read

The short answer

The study design chooses the test—not the appearance of two columns.

Use a paired t test when each value in one condition has a meaningful one-to-one partner in the other condition: the same patient measured twice, matched specimens, or deliberately paired experimental units. Use an unpaired test when observations in the two groups come from independent units.

Decision rule: if row 7 in column A belongs with row 7 in column B for a scientific reason established by the design, preserve that pair in the analysis.

The canonical sleep experiment

R's sleep dataset records the increase in sleep, relative to control, produced by two soporific drugs in the same ten patients. The R documentation explicitly warns that the group labels can be misleading: these are repeated measurements on ten people, not two independent groups.

Before-after plot of the Student sleep dataset Ten lines connect each patient's additional sleep under drug one and drug two. Nine rise or stay level; one pair shows the largest increase. Drug 1 Drug 2 6 h −2 h Patient 1: 0.7 to 1.9 extra hours Patient 2: −1.6 to 0.8 extra hours Patient 3: −0.2 to 1.1 extra hours Patient 4: −1.2 to 0.1 extra hours Patient 5: −0.1 to −0.1 extra hours Patient 6: 3.4 to 4.4 extra hours Patient 7: 3.7 to 5.5 extra hours Patient 8: 0.8 to 1.6 extra hours Patient 9: 0 to 4.6 extra hours Patient 10: 2 to 3.4 extra hours
Each line is one patient. The pairing is information: it shows how the response changed within a person.

What changes when pairing is ignored?

Paired t test · design preserved t(9) = −4.062, P = 0.002833

Mean drug 1 − drug 2 difference: −1.58 h; 95% CI −2.46 to −0.70 h.

Unpaired t test · pairing discarded t(18) = −1.861, P = 0.07919

The same 20 numbers are treated as if they came from 20 independent people.

The mean difference is identical in both calculations. The uncertainty is not. The paired calculation works on ten within-patient differences, removing stable between-patient variation from the error term. This is not permission to choose the test that produces a smaller P value; the pairing must come from the design.

What the paired t test assumes

  • Pairs are defined before looking at the outcome.
  • Different pairs are independent of one another.
  • The outcome is continuous and the pair differences are meaningfully numeric.
  • The distribution of the pair differences is sufficiently compatible with the t model.
Important limitation: this small historical dataset contains one relatively large difference (−4.6 h), and Plotwright's omnibus normality diagnostic flags the ten differences. Inspect the difference plot and consider a prespecified robust or nonparametric sensitivity analysis; do not treat the canonical P value as a universal recipe.

A compact reporting template

“Sleep increase was compared within the same ten patients using a two-sided paired t test. The mean drug 1 − drug 2 difference was −1.58 hours (95% CI −2.46 to −0.70), t(9) = −4.06, P = 0.00283. Individual paired observations and the distribution of differences were inspected.”

Adapt that text to the actual design, analysis plan, diagnostics and reporting standard for your study. Software cannot establish whether observations were truly paired.

Sources and reproducibility

  1. R documentation: Student's sleep data—dataset structure, provenance and paired t-test example.
  2. NIST/SEMATECH handbook: analysis of paired observations—definition and paired-test formulation.
  3. Plotwright statistical validation—the executable reference tolerance for this result is |Δt| ≤ 5×10⁻⁴ and |ΔP| ≤ 1×10⁻⁵.

Keep the pairing visible from data to figure.

Plotwright creates the paired result, difference diagnostics, editable before-after graph and methods text in one inspectable project.