BCompare groups · Guide test 010
Paired Student t test
Tests the mean within pair difference against a specified value, usually zero.
Do it in CodeSplash
In the app, set it up in Analyze with this method:
- Paired t-test — Did the same subjects change between two measurements?
Do it in CodeSplash Run this test on your own data, in Python or R.
Bench
Change the design, drag the data, move α. The statistic, its reference distribution and the verdict follow.
Bench · Paired t test
Alternative
The statistic's distribution if the design's true effect is real.
Your data
Drag a point or use ↑/↓ to change itIf H₀ were true
- The reference: how t varies across samples when H₀ is true.
- Your statistic, from the data above.
- The p-value: the area at least as extreme as yours (p = .013).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- the mean of the within-pair differences
- the SD of the differences
- the number of pairs
The verdict
t(14) = 2.84, p = .013, d_z = 0.73
p ≤ α = .050: reject H₀
Effect size: standardized mean difference d_z = 0.733
A one-sample t test on the differences: pairing removes the between-unit spread, which is why it can detect changes a two-sample test would miss.
- Statistic
- 2.837
- p-value
- 0.0132
Paired t test on Before: n = 15; After: n = 15: t(14) = 2.84, p = .013, d_z = 0.73. The p-value is below α = .050, so the data are hard to reconcile with H₀.
Question and hypotheses
H0: E(D)=Δ0 for within pair differences D; H1: E(D) differs.
Assumptions
Pairs are independent of one another and pairing is meaningful. Exact inference assumes the differences are normally distributed; the two marginal measurements need not each be normal or have equal variances.
Formula
Parameters and notation
n is the number of complete pairs, d̄ their mean difference, and sd their sample standard deviation. Δ0 is the target change.
Structure of the method
Construct one prespecified difference per matched pair and apply the one-sample t procedure to those differences. The denominator estimates variability of change, automatically incorporating within-pair covariance. Exactness concerns normality of differences, not normality of both original measurements or equality of their marginal variances.
Estimated and nuisance parameters
Estimate the mean and variance of complete-pair differences. The matching key, direction of subtraction, target change, and pair count define the design. The effective sample size is the number of independent pairs, not twice that number and not the number of repeated records within a person.
Settings and design choices
Prespecify pairing, treatment of incomplete pairs, alternative direction, alpha, and any clinically meaningful change threshold. Multiple timepoints do not justify selecting the most favorable before/after pair. An aggregation rule for repeated readings within a pair should reflect the experimental unit and measurement objective.
Fitting and adaptation
Recompute differences after reconciling identifiers or measurement units, and refit their variance. A paired bootstrap resamples whole pairs, preserving the matching relation. More than two occasions or correlated pairs within higher-level clusters calls for a repeated-measures or hierarchical model rather than an unmodified paired t test.
Sensitivity and robustness
A single extreme change can dominate a small sample even when each marginal distribution appears reasonable. Informative missingness can bias complete-pair estimates. Reversing subtraction changes the signed statistic and one-sided hypothesis; it must also reverse the reported effect interpretation and confidence interval consistently.
How to use and calibrate
Compute one difference per pair and perform a one sample t test on those differences. Plot differences and inspect extreme values; report the average paired change and interval.
Example application
With 20 paired readings, mean change 3 and sd=4, t=3/(4/√20)=3.354 with 19 degrees of freedom.
Interpretation and pitfalls
Watch out
Using an independent groups test loses the covariance benefit. Multiple observations from one person are not automatically independent pairs. Complete case analysis may be biased when missingness is informative.
What changed in edition 2
- New sections: structure of the method, estimated and nuisance parameters, settings and design choices, fitting and adaptation, sensitivity and robustness.
Python and R
Two-sided alpha=0.05; the paired example treats corresponding positions as measurements on the same unit.
Validated — Executed successfully in the validation environment · needs numpy, scipy
import numpy as np
from scipy import stats
rng = np.random.default_rng(2026)
x = np.array([4.2,5.1,5.4,4.8,6.0,5.8,4.9,5.6,6.2,5.0])
y = np.array([4.0,4.4,4.8,5.0,5.1,4.3,4.7,4.6,5.2,4.9])
print(stats.ttest_rel(x,y))
Output
TtestResult(statistic=np.float64(3.643993485805121), pvalue=np.float64(0.005367433950508523), df=np.int64(9))
Validated — Executed successfully in the validation environment · needs Base/standard library
x <- c(4.2,5.1,5.4,4.8,6.0,5.8,4.9,5.6,6.2,5.0)
y <- c(4.0,4.4,4.8,5.0,5.1,4.3,4.7,4.6,5.2,4.9)
print(t.test(x,y,paired=TRUE))
Output
Paired t-test
data: x and y
t = 3.644, df = 9, p-value = 0.005367
alternative hypothesis: true mean difference is not equal to 0
95 percent confidence interval:
0.2275256 0.9724744
sample estimates:
mean difference
0.6Sources
- R Student t testsstat.ethz.ch
- t.teststat.ethz.ch
- Statistics guide v4 (historical):
- R: Executed successfully in the validation environment
- Reference's record:
- Edition 2 review: Python: executed · R: not executed (Rscript unavailable). Python: Ran in the reference's review, on this exact code. R: Reviewed but not run: R wasn't available to the reference's authors.
From the CodeSplash statistics guide (v4), entry 010, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT010.