Method · Statistics Library

Paired t-test

The paired t-test compares two related measurements on the same units (before/after, matched pairs) by testing whether the mean of the within-pair differences is zero, reporting Cohen's d_z as the paired-design effect size.

Topic indexA reference reading outside the guided chapter sequence

Understand the idea

When the SAME units are measured twice (a patient's blood pressure before and after treatment, the same participant under two conditions), the paired t-test is the right tool, because it works entirely with the DIFFERENCES between each pair, not the raw values in each column. Person-to-person variation (some people just run higher or lower than others regardless of treatment) cancels out automatically when you look at each person's own change rather than comparing two separate groups' averages.

This is genuinely more powerful than treating the two measurements as if they came from separate, unrelated groups, precisely because pairing removes a whole source of noise (between-person variation) that an independent two-sample comparison would have to fight through. The assumption to check is about the DIFFERENCES specifically, not the two original columns: it's the SPREAD OF THE CHANGES that needs to be roughly normal, which is a different and usually easier bar to clear than requiring the original measurements themselves to be normal.

Cohen's d_z (the paired-design effect size) standardizes the average within-pair change by how much those changes vary from person to person, using the same negligible/small/medium/large benchmarks as any other Cohen's d. As with any t-test, choose whether you're testing for a change in either direction, or specifically an increase, or specifically a decrease, BEFORE looking at the data; picking the direction that happens to match what you already see afterward inflates your real false-positive rate.

The paired t-test is also called the dependent samples t-test, and a before-after t-test is its most common use.

Practitioner explanation

KernelStats computes t = d-bar/(s_d/sqrt(n)) via scipy.stats.ttest_rel, where d = x1-x2 for each row (the two columns must be ROW-ALIGNED, same unit per row), with Cohen's d_z = d-bar/s_d as the paired-design effect size. As with the one-sample test, a careful distinction is drawn between two different degenerate cases: when s_d is exactly 0 AND the mean difference is exactly 0, d_z=0 is the mathematically correct value; but when s_d is 0 while the mean difference is nonzero (every pair changed by EXACTLY the same amount, the common case of two identical or near-identical columns), d_z is reported as UNDEFINED (None) rather than a misleading zero.

Selecting the SAME column for both x1 and x2 is refused explicitly by name rather than silently producing a degenerate all-zero-difference result, a specific, documented guard against a genuinely easy-to-make Inspector mistake (both dropdowns default to the same continuous-column list). Both measurement columns are validated with the SAME numeric-coercion guard used across KernelStats's hypothesis tests: a text-coded numeric column ('10.5', '11.2') still runs, but a genuinely non-numeric column is refused by name with a clear 400 rather than escaping as a raw conversion error.

As with the one-sample t-test, the confidence interval reported is ALWAYS the conventional two-sided interval, explicitly labeled as such regardless of which alternative direction was tested, and R's one-tailed convention (a one-sided bound [L, infinity)) is named directly as the reason the two tools' numbers will not match on a one-tailed run, a stated convention difference, not a computational disagreement. A minimum-detectable-effect figure at 80% power is reported, computed purely from the pair count, alpha, and sidedness, never from the observed d_z, deliberately avoiding the post-hoc power fallacy the product's own module documentation names explicitly.

When to use it

Consider it when

You have two numeric columns that are ROW-ALIGNED (each row represents the same unit measured twice: before/after, two conditions on the same participant, matched pairs like twin studies or left/right measurements).

Use caution when

The two measurements come from different, unrelated units (use the two-sample t-test instead, which does not assume pairing), the within-pair differences are severely non-normal at a small sample size (use the Wilcoxon signed-rank test on the differences), or the same column is accidentally selected for both roles (refused explicitly, since pairing a column with itself produces an all-zero, meaningless difference).

Formulas and symbols

Paired t statistic

t=dˉsd/nt = \dfrac{\bar d}{s_d/\sqrt{n}}

d-bar the mean of the within-pair differences (x1-x2); s_d the sample SD of those differences; n the number of matched pairs.

Cohen's d_z (paired)

dz=dˉsdd_z = \dfrac{\bar d}{s_d}

The paired-design standardized mean difference. Undefined (not zero) when s_d=0 but the mean difference is nonzero.

Assumptions and checks

  • Independence of observations. The pairs themselves must be independent of one another (the two measurements within a pair are naturally dependent, which is exactly what pairing accounts for); dependence BETWEEN pairs (e.g. pairs sharing a common batch or cluster) makes the standard error too small.

    In KernelStats: Not checkable from the data alone: it is a property of how the data were collected.

  • Normality (of residuals, not of the raw data). At small n, strong skew or outliers in the within-pair differences distort both the p-value and the confidence interval; at moderate to large n the Central Limit Theorem makes the test fairly robust.

    In KernelStats: Shapiro-Wilk for 3 <= n <= 5000, and Anderson-Darling for n >= 8 (becoming the primary verdict above n = 5000), both computed on the within-pair differences and reported directly on the card.

Alternatives

  • Two-Sample t-Test. The two measurements come from independent, unrelated groups of units rather than the same units measured twice.
  • Wilcoxon Signed-Rank Test. The within-pair differences are clearly non-normal at a small sample size, or the response is ordinal rather than a continuous interval measurement.

Worked example

Scenario

Blood pressure measured on 30 patients before and after a 12-week treatment.

Result

t(29) = -4.12, p < .001, mean difference = -8.3 mmHg, 95% CI [-12.4, -4.2], Cohen's d_z = 0.75 (medium-to-large).

Interpretation

Blood pressure dropped significantly between the two measurements, with a medium-to-large standardized effect (without an untreated comparison group, the drop cannot by itself be attributed to the treatment rather than to time or regression to the mean), and the confidence interval places the true average reduction somewhere between about 4 and 12 mmHg; the pairing (comparing each patient to themselves) is what makes this a much more sensitive comparison than treating before and after as two separate, unrelated groups of 30 patients each.

Common misconceptions

Misconception

A paired t-test and a two-sample t-test on the same two columns should give essentially the same answer, since both compare two sets of numbers.

Correction

Pairing specifically REMOVES between-subject variation from the comparison by working with within-pair DIFFERENCES, while a two-sample test treats the two columns as if they came from entirely separate, unrelated groups. When the pairing is genuine (each row is truly the same unit measured twice), the paired test is typically far more powerful, and treating paired data as if it were independent wastes real information and can produce a very different (usually less significant) result.

Misconception

The normality assumption for a paired t-test requires each of the two original measurement columns to be normally distributed.

Correction

The relevant normality assumption is about the WITHIN-PAIR DIFFERENCES (d = x1 - x2), not the two original columns separately. Two individually non-normal columns can still produce a well-behaved, roughly normal set of differences, and that is the only distribution this test's exact inference actually depends on.

References

  1. NIST/SEMATECH e-Handbook of Statistical Methods, §3.3.5 Comparing two paired samples, NIST/SEMATECH (2012), §3.3.5.
  2. Calculating and reporting effect sizes to facilitate cumulative science: a practical primer for t-tests and ANOVAs, Lakens, D. (2013), Frontiers in Psychology, 4, 863.