🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
đŸ’ŧ Servicesâ„šī¸ Aboutâœ‰ī¸ ContactView Pricing Plansfrom $10

t-Tests: One-Sample, Paired, and Welch Compared

StatisticsParametric TestsđŸŸĸ Free Lesson

One test family, four different questions

Every t-test answers the same underlying question — is this observed difference in means large relative to the noise in the data — but the phrasing of the question determines which variant you must use. The one-sample test compares a single group against a fixed benchmark. The paired test compares two measurements taken on the same units, before and after or left and right. The two independent-samples tests compare separate groups, and they come in two flavours that differ only in whether equal variances are assumed.

The independent-samples choice is where most analyses go quietly wrong. The classic pooled-variance t-test assumes both groups share a common variance, an assumption that is invisible when it holds and badly distorting when it does not. Welch's t-test drops the assumption by estimating the standard error separately from each group, and the cost in power when the assumption happens to be true is negligible. Because of that asymmetry — big downside, tiny upside — Welch's is the sensible default for any comparison of two independent means.

SituationCorrect testFunction in SciPyDegrees of freedom
One group against a known valueOne-sample tttest_1samp(x, mu0)n minus one
Two independent groups, equal variancesPooled tttest_ind(x, y, equal_var=True)n1 plus n2 minus two
Two independent groups, unequal variancesWelch tttest_ind(x, y, equal_var=False)Satterthwaite approximation
Two measurements on the same unitsPaired tttest_rel(x, y)n pairs minus one

Picking the right variant

Start from the data structure rather than the formula. If there is one column of numbers and a reference value, use the one-sample test. If there are two columns describing the same rows — a score before training and after training for each employee — the observations are matched and the paired test is required, because pairing removes the between-subject variation that would otherwise dominate the error term. Treating matched data as independent discards that advantage and typically costs you several points of power.

If the two columns describe different people entirely, the groups are independent and the question becomes pooled versus Welch. Check with Levene's test or simply look at the ratio of the two standard deviations; if they differ by more than about fifty percent in either direction, the pooled formula's standard error is wrong and the p-value is miscalibrated. Since Welch is nearly as powerful under equality and strictly safer under inequality, the practical answer is to use it unless you have a specific reason not to.

The pooled and Welch formulas side by side

Both statistics have the same numerator: the difference between the two sample means. They differ entirely in the denominator. The pooled version estimates one common standard deviation from both groups, weighted by their degrees of freedom, then multiplies it by the square root of the sum of the reciprocals of the sample sizes. It is efficient when the common-variance story is true.

Welch's version instead adds the two group-specific variances divided by their respective sample sizes, each term estimated independently. When the group sizes are unequal, this also protects against the worst failure mode of pooling: a small group with a much larger variance can be badly underweighted by the pooled estimate, making the standard error too small and the test too liberal. Welch adjusts the degrees of freedom downward in that situation, sometimes substantially, which widens the reference distribution and restores the error rate.

Assumptions and how they fail

Independence is the assumption that cannot be repaired after the fact. If observations share a cluster — students within classrooms, measurements within patients, transactions within accounts — the effective sample size is smaller than the row count and the test is anti-conservative. Fix this at design time by sampling across clusters, or at analysis time by modelling the clustering directly rather than pretending each row is an independent draw.

Normality matters for small samples and is irrelevant for large ones, thanks to the central limit theorem. For n below thirty, inspect a Q-Q plot or run a Shapiro-Wilk test on the residuals; heavy skew or a strong outlier can push a t-test well off its nominal level. Equal variances matter only for the pooled variant, and are checked with Levene's test, which is itself robust to non-normality. Continuous, unbounded measurement on a sensible scale is the fourth requirement — an ordinal rating with five levels is better served by a rank-based alternative.

Effect size and the interval you should also report

A p-value answers whether a difference exists; it says nothing about whether the difference matters. Cohen's d divides the mean difference by the pooled standard deviation, converting the raw gap into units of natural variability. The conventional benchmarks are zero point two for small, zero point five for medium, and zero point eight for large, and they are only heuristics — a zero point two shift in a manufacturing defect rate can be worth millions, while a zero point eight shift in a lab curiosity may be worthless.

The confidence interval for the mean difference is the single most informative companion to the p-value. It shows the range of effect sizes still compatible with the data, and its width reveals how much uncertainty remains. A wide interval containing both a meaningful benefit and a meaningful harm means the study cannot decide the question, whatever the p-value says. In machine learning practice the same logic applies to comparing two models across cross-validation folds: the folds are matched by split, so a paired test on the per-fold differences is the correct comparison, and the interval on that difference is what you should plot.

All four variants in Python

python
import numpy as np
from scipy import stats

def cohens_d_independent(a, b):
    na, nb = len(a), len(b)
    pooled = np.sqrt(((na - 1) * np.var(a, ddof=1) +
                      (nb - 1) * np.var(b, ddof=1)) / (na + nb - 2))
    return (np.mean(a) - np.mean(b)) / pooled

def mean_difference_ci(a, b, confidence=0.95, welch=True):
    na, nb = len(a), len(b)
    diff = np.mean(a) - np.mean(b)
    va, vb = np.var(a, ddof=1) / na, np.var(b, ddof=1) / nb
    if welch:
        se = np.sqrt(va + vb)
        df = (va + vb) ** 2 / (va ** 2 / (na - 1) + vb ** 2 / (nb - 1))
    else:
        pooled = ((na - 1) * np.var(a, ddof=1) +
                  (nb - 1) * np.var(b, ddof=1)) / (na + nb - 2)
        se = np.sqrt(pooled * (1 / na + 1 / nb))
        df = na + nb - 2
    crit = stats.t.ppf((1 + confidence) / 2, df)
    return diff - crit * se, diff + crit * se, df

rng = np.random.default_rng(11)
group_a = rng.normal(78, 12, 25)
group_b = rng.normal(84, 18, 30)

print("pooled   :", stats.ttest_ind(group_a, group_b, equal_var=True))
print("welch    :", stats.ttest_ind(group_a, group_b, equal_var=False))
print("Levene   :", stats.levene(group_a, group_b))
print("d        :", round(cohens_d_independent(group_a, group_b), 3))
print("95% CI   :", np.round(mean_difference_ci(group_a, group_b)[:2], 2))

The pooled and Welch statistics differ here because the group sizes and variances differ, and Levene's test tells you whether that difference is large enough to worry about. The interval at the end is the quantity to quote alongside whichever p-value you report.

The paired variant is where the design advantage becomes visible.

python
import numpy as np
from scipy import stats

rng = np.random.default_rng(5)
subjects = rng.normal(100, 20, 40)
before = subjects + rng.normal(0, 4, 40)
after = subjects + rng.normal(-6, 4, 40)

diff = after - before
t, p_paired = stats.ttest_rel(after, before)
t_indep, p_indep = stats.ttest_ind(before, after, equal_var=False)

print(f"paired   t={t:.3f}  p={p_paired:.2e}")
print(f"indep.   t={t_indep:.3f}  p={p_indep:.2e}")
print("mean change:", round(float(diff.mean()), 2),
      " sd of change:", round(float(diff.std(ddof=1)), 2))

d_paired = diff.mean() / diff.std(ddof=1)
print("paired effect size (dz):", round(float(d_paired), 3))

Both tests detect the same underlying change, but the paired test removes the large between-subject variation and produces a much larger statistic with a much smaller p-value. That gain is not a trick; it is the reward for matching the test to the design.

t-test mistakes that change the answer

Common Mistakes

Running an independent t-test on before-and-after measurements

Fix: Use the paired test on within-subject differences; it removes subject-level variation and gains real power.

Choosing pooled variance because it is the textbook default

Fix: Default to Welch; it costs almost nothing when variances are equal and protects you when they are not.

Testing normality on the raw groups for a paired test

Fix: Check the distribution of the differences, which is the quantity the test actually models.

Ignoring clustering or repeated measures inside the groups

Fix: Independence is violated by design; aggregate per cluster or fit a mixed model instead.

Quoting only the p-value

Fix: Report the mean difference, Cohen's d, and the confidence interval so the magnitude is visible.

Dropping outliers because they make the test non-significant

Fix: Pre-register the exclusion rule, or run a robust or rank-based alternative and report both.

Best Practices

  • Match the test to the data structure before looking at the p-value.
  • Use Welch's t-test as the default for two independent groups.
  • Always pair the p-value with an effect size and its confidence interval.
  • Inspect a Q-Q plot when n is below thirty.
  • For model comparisons, test the per-fold differences rather than the two score distributions.

t-tests in one page

Where to go next

CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-10-13

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Need Expert Mathematics Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement