College Statistics • Hypothesis Testing

t-Test for Difference of Means — Hypothesis Test for Difference of Means

Determine whether two population means differ significantly using sample data and the t-distribution.

College Statistics subject emblem with a scatter plot, summation notation, and frequency columns.
Inside this lesson 10 sections 5 questions 9 figures

SECTION 1

Historical Context & Motivation

The need to compare two groups — whether two treatments, two populations, or two conditions — has driven scientific inquiry for centuries. Before formal statistical methods existed, researchers relied on subjective judgment to decide whether observed differences were meaningful or merely artifacts of sampling variability. The development of the t-test in the early twentieth century provided a rigorous, probabilistic framework for answering this fundamental question: are the means of two populations truly different, or could the observed discrepancy have arisen by chance alone?

1908 • Student's t-Distribution

William Sealy Gosset, publishing under the pseudonym "Student" while working at Guinness Brewery, derived the t-distribution to handle small-sample inference when the population variance is unknown. His landmark paper in Biometrika laid the foundation for modern hypothesis testing with limited data.

1925 • Fisher Formalizes Hypothesis Testing

Ronald A. Fisher expanded and formalized the use of the t-test within his broader framework of significance testing, introducing the concept of p-values and popularizing the α = 0.05 threshold. Fisher's Statistical Methods for Research Workers made these tools accessible to experimentalists across disciplines.

1933 • Neyman–Pearson Framework

Jerzy Neyman and Egon Pearson introduced the concepts of Type I and Type II errors, power analysis, and the formal null/alternative hypothesis structure. Their framework gave the two-sample t-test its modern logical architecture, distinguishing it from Fisher's significance testing approach.

1947 • Welch's Correction

Bernard L. Welch proposed a modification of the two-sample t-test that does not assume equal population variances. Welch's t-test uses an approximation to the degrees of freedom (the Satterthwaite–Welch equation), making the procedure robust in heteroscedastic settings and becoming the default in many modern software packages.

The central question addressed by the two-sample t-test remains deceptively simple: given two samples drawn from potentially different populations, can we conclude that the population means μ₁ and μ₂ are not equal? Answering this question with statistical rigor requires quantifying sampling variability, choosing an appropriate test statistic, and evaluating the probability of observing our data under the null hypothesis. This lesson walks through that entire process.

SECTION 2

Core Principles & Definitions

Before diving into formulas, it is essential to understand the conceptual pillars on which the two-sample t-test rests. Each principle below represents a necessary condition or foundational idea that governs when and how the test may be applied. Mastering these principles ensures that you do not merely plug numbers into equations but rather understand the logic of statistical inference that generates those equations.

1

Null & Alternative Hypotheses

The null hypothesis (H₀) asserts that the two population means are equal: μ₁ − μ₂ = 0. The alternative hypothesis (H₁) asserts they differ (two-tailed), or that one exceeds the other (one-tailed). All inferential conclusions are framed relative to these competing claims.
2

Sampling Distribution of the Difference

Under H₀, the difference of sample means (x̄₁ − x̄₂) follows a distribution centered at zero. When the population standard deviations are unknown and estimated from the sample, this distribution is modeled by the t-distribution, which has heavier tails than the standard normal and accounts for additional uncertainty.
3

Degrees of Freedom

The shape of the t-distribution depends on the degrees of freedom (df). For the pooled (equal-variance) t-test, df = n₁ + n₂ − 2. For Welch's t-test, df is computed via the Satterthwaite approximation and is typically not an integer. As df increases, the t-distribution approaches the standard normal.
4

Significance Level (α)

The significance level α is the pre-specified probability of committing a Type I error — rejecting a true H₀. Common choices are 0.05, 0.01, and 0.10. The p-value is compared to α: if p ≤ α, we reject H₀; otherwise, we fail to reject.
5

Assumptions

The t-test requires that (1) both samples are drawn independently, (2) the observations within each sample are independent, and (3) the populations are approximately normally distributed or the sample sizes are large enough for the CLT to apply. The pooled version further assumes equal population variances.
✦

KEY TAKEAWAY

Think of the two-sample t-test like weighing evidence in a courtroom. The null hypothesis is the presumption of innocence — the means are equal until proven otherwise. Your sample data is the evidence, and the t-statistic measures how compelling that evidence is. The p-value is the probability that equally strong (or stronger) evidence could appear even if the defendant were truly innocent. Only when that probability drops below your chosen threshold α do you 'convict' — that is, reject H₀.

SECTION 3

Visual Explanation — Sampling Distributions Under H₀

A visual representation of the t-test logic clarifies why we compare the observed difference to a theoretical distribution. The diagram below shows the sampling distribution of x̄₁ − x̄₂ under H₀, centered at zero. The shaded rejection regions in the tails represent the critical values beyond which we would reject H₀ at α = 0.05 (two-tailed). The position of the observed t-statistic relative to these critical values determines our conclusion.

Sampling Distribution of x̄₁ − x̄₂ Under H₀ (Two-Tailed)0(μ₁ − μ₂ under H₀)−t*+t*α/2α/2t_obsObservedt-statisticFail to reject H₀ regionRejection region (α/2 each tail)Observed test statistic
The bell-shaped curve represents the t-distribution under H₀, centered at 0. The red shaded tails mark the rejection regions at α/2 each. The gold dashed line shows an observed t-statistic that falls within the fail-to-reject region. If it had landed beyond ±t*, we would reject H₀.

Notice the key decision rule: the observed t-statistic is compared against the critical values ±t* obtained from the t-distribution table (or software) at the chosen significance level and appropriate degrees of freedom. Equivalently, one can compute the p-value — the total probability in both tails beyond |t_obs| — and compare it directly to α. If the p-value is less than or equal to α, the evidence against H₀ is deemed statistically significant. The visual emphasizes that the rejection decision is fundamentally about whether the observed difference is extreme relative to what random sampling alone would produce.

SECTION 4

Mathematical Framework

The two-sample t-test comes in two primary variants depending on whether we can assume equal population variances. In both cases, the test statistic has the same general form: the observed difference in sample means divided by the estimated standard error of that difference. What differs is how the standard error is estimated and how the degrees of freedom are computed.

Pooled (Equal-Variance) Two-Sample t-Test

POOLED TEST STATISTIC

t=(xˉ1−xˉ2)−(μ1−μ2)0/√[sp2(1/n1+1/n2)]t = (x̄₁ − x̄₂) − (μ₁ − μ₂)₀ / √[ s²_p (1/n₁ + 1/n₂) ]

where x̄₁ and x̄₂ are the sample means, (μ₁ − μ₂)₀ is the hypothesized difference (usually 0), n₁ and n₂ are the sample sizes, and s²_p is the pooled sample variance.

POOLED VARIANCE

sp2=[(n1−1)s12+(n2−1)s22]/(n1+n2−2)s²_p = [ (n₁ − 1)s₁² + (n₂ − 1)s₂² ] / (n₁ + n₂ − 2)

The pooled variance is a weighted average of the two sample variances, with weights proportional to their respective degrees of freedom (n₁ − 1 and n₂ − 1). This estimate uses the assumption that σ₁² = σ₂².

DEGREES OF FREEDOM (POOLED)

df=n1+n2−2df = n₁ + n₂ − 2

The pooled test has a clean integer degrees of freedom. Each sample contributes n − 1 degrees of freedom to the variance estimate.

Welch's (Unequal-Variance) Two-Sample t-Test

WELCH'S TEST STATISTIC

t=(xˉ1−xˉ2)−(μ1−μ2)0/√(s12/n1+s22/n2)t = (x̄₁ − x̄₂) − (μ₁ − μ₂)₀ / √( s₁²/n₁ + s₂²/n₂ )

Welch's version does not pool the variances. Each sample's variance is divided by its own sample size, preserving the separate variance structure.

SATTERTHWAITE DEGREES OF FREEDOM

df=(s12/n1+s22/n2)2/[(s12/n1)2/(n1−1)+(s22/n2)2/(n2−1)]df = ( s₁²/n₁ + s₂²/n₂ )² / [ (s₁²/n₁)² / (n₁ − 1) + (s₂²/n₂)² / (n₂ − 1) ]

This approximation yields a non-integer df that is then used to look up (or compute) the critical value from the t-distribution. Most statistical software handles this automatically.

💡

When to Use Which?

If a preliminary test (such as Levene's test) or domain knowledge suggests equal variances, the pooled t-test is appropriate. However, many statisticians recommend Welch's t-test as the default because it performs well even when variances are equal (with only a slight loss of power) and is far more robust when they are not. Software such as R's t.test() uses Welch's version by default.

SECTION 5

Step-by-Step Procedure & Decision Flowchart

Conducting a two-sample t-test follows a structured procedure that mirrors the general hypothesis-testing workflow. The flowchart below maps the entire decision process from initial problem setup through to conclusion, highlighting the branch point where you decide between the pooled and Welch versions of the test.

Two-Sample t-Test Decision Flowchart1. State H₀ and H₁2. Choose significance level α3. Check assumptions (normality, independence)Equalvariances?YesNo / Unknown4a. Pooled t-testdf = n₁+n₂−24b. Welch's t-testdf ≈ Satterthwaite5. Compute t5. Compute t6. Compare p-value to α → Conclude
The flowchart traces the complete hypothesis-testing procedure. The key branch point at step 4 asks whether the equal-variance assumption is tenable. Both paths converge at the final comparison of the p-value against α.
  1. Step 1: Formulate H₀: μ₁ − μ₂ = 0 and H₁: μ₁ − μ₂ ≠ 0 (or a one-tailed alternative if theory justifies directionality).
  2. Step 2: Select α (e.g., 0.05) before collecting or analyzing data.
  3. Step 3: Verify independence and normality assumptions. Use histograms, Q–Q plots, or Shapiro–Wilk tests. For large samples (n > 30 per group), the Central Limit Theorem provides robustness.
  4. Step 4: Assess equal variance (e.g., Levene's test, or a rule of thumb that the ratio of the larger to the smaller sample variance does not exceed 4). Choose pooled or Welch accordingly.
  5. Step 5: Compute the test statistic t and the associated degrees of freedom.
  6. Step 6: Determine the p-value from the t-distribution (or compare t to the critical value t*). State your conclusion in context.

SECTION 6

Worked Example — Comparing Exam Scores

A university professor wants to determine whether students who attend supplemental instruction (SI) sessions perform differently on the final exam compared to students who do not. A random sample of n₁ = 15 SI students has a mean score of x̄₁ = 82.4 with s₁ = 7.3, while a random sample of n₂ = 18 non-SI students has a mean score of x̄₂ = 76.1 with s₂ = 9.8. Both populations are approximately normally distributed. We will conduct a two-tailed test at α = 0.05. Since the sample variances differ noticeably (s₂ is about 1.8 times s₁), we will use Welch's t-test.

Two-Sample t-Test (Welch's Version)

  1. 1

    Step 1 — State the Hypotheses

    H₀: μ₁ − μ₂ = 0 (the population means are equal). H₁: μ₁ − μ₂ ≠ 0 (the population means differ). This is a two-tailed test with α = 0.05.
  2. 2

    Step 2 — Identify the Given Values

    SI group: x̄₁ = 82.4, s₁ = 7.3, n₁ = 15. Non-SI group: x̄₂ = 76.1, s₂ = 9.8, n₂ = 18.
  3. 3

    Step 3 — Compute the Standard Error

    SE = √(s₁²/n₁ + s₂²/n₂) = √(7.3²/15 + 9.8²/18) = √(53.29/15 + 96.04/18) = √(3.5527 + 5.3356) = √8.8883 ≈ 2.981.
    SE ≈ 2.981
  4. 4

    Step 4 — Compute the Test Statistic

    t = (x̄₁ − x̄₂) / SE = (82.4 − 76.1) / 2.981 = 6.3 / 2.981 ≈ 2.113.
    t ≈ 2.113
  5. 5

    Step 5 — Compute Degrees of Freedom (Satterthwaite)

    df = (s₁²/n₁ + s₂²/n₂)² / [(s₁²/n₁)²/(n₁−1) + (s₂²/n₂)²/(n₂−1)] = (3.5527 + 5.3356)² / [(3.5527)²/14 + (5.3356)²/17] = (8.8883)² / [12.6216/14 + 28.4686/17] = 79.0019 / [0.9015 + 1.6746] = 79.0019 / 2.5761 ≈ 30.67.
    df ≈ 30.67 (use df = 30 conservatively, or exact value in software)
  6. 6

    Step 6 — Find the p-Value and Conclude

    Using a t-distribution with df ≈ 30.67, the two-tailed p-value for t = 2.113 is approximately 0.043. Since p = 0.043 < α = 0.05, we reject H₀. There is sufficient evidence at the 5% significance level to conclude that the mean exam scores differ between SI and non-SI students.
    p ≈ 0.043 → Reject H₀
ℹ

Interpreting the Result in Context

Statistical significance does not automatically imply practical importance. The observed difference of 6.3 points may or may not be educationally meaningful. Reporting a confidence interval for μ₁ − μ₂ (approximately 0.2 to 12.4 points using the same SE and t*) gives additional insight into the plausible magnitude of the effect and aids in evaluating practical significance.

SECTION 7

Strengths, Limitations & Variant Comparisons

The two-sample t-test is one of the most widely used inferential tools, but it is not universally applicable. Understanding its strengths and limitations helps you recognize when the t-test is the right choice, when a modification is needed, and when an entirely different procedure should be employed.

FeaturePooled t-TestWelch's t-Test
Variance assumptionRequires σ₁² = σ₂²No equal-variance assumption
Degrees of freedomn₁ + n₂ − 2 (integer)Satterthwaite approximation (non-integer)
Power when σ₁² = σ₂²Slightly higher (uses all df)Slightly lower (conservative df)
Robustness when σ₁² ≠ σ₂²Can inflate Type I error rateMaintains nominal α
Default in softwareMust be explicitly requestedDefault in R, Python (scipy)
Best use caseBalanced designs with known equal variancesGeneral-purpose default for two independent samples

Comparison of Pooled vs. Welch's Two-Sample t-Test

Common Limitations of Both Variants

  • Normality sensitivity for small samples: When sample sizes are below 15 and the population distribution is heavily skewed or contains outliers, the t-test's p-values may be unreliable. Nonparametric alternatives such as the Mann–Whitney U test may be preferable.
  • Independence requirement: The test assumes observations are independent both within and between groups. Paired or repeated-measures data require a paired t-test instead.
  • Two groups only: Comparing three or more groups simultaneously requires ANOVA, not multiple t-tests (which inflate the familywise error rate).
  • Sensitive to outliers: Because the mean and variance are not robust measures, extreme values can disproportionately affect the test statistic.
✦

KEY TAKEAWAY

Choosing between the pooled and Welch t-test is similar to choosing between a fixed-size wrench and an adjustable wrench. The fixed wrench (pooled) works perfectly when the bolt matches, giving you a snug fit (maximum power). The adjustable wrench (Welch) may sacrifice a tiny amount of precision when the variances truly are equal, but it handles bolts of any size — a far safer choice when you are unsure. In modern practice, default to Welch unless you have strong reason to assume equal variances.

SECTION 8

Connection to Advanced Methods

The two-sample t-test is the simplest member of a family of procedures for comparing group means. As research questions grow more complex — involving multiple groups, covariates, or non-independent observations — the t-test generalizes into more powerful frameworks. Understanding these connections will help you see the t-test not as an isolated tool but as a foundational building block of the general linear model.

Two-Sample t-TestAdvanced Generalization
Compares 2 independent group meansOne-Way ANOVA compares k ≥ 2 group means simultaneously using the F-statistic (t² = F when k = 2)
No covariates or blocking factorsANCOVA controls for continuous covariates while comparing group means
Assumes normality of populationsMann–Whitney U Test is a nonparametric alternative that tests for stochastic dominance without normality
Independent samples onlyPaired t-Test handles dependent (matched) observations by analyzing the differences within pairs
Single outcome variableHotelling's T² extends to multivariate settings with p correlated response variables
Fixed-effects comparisonLinear Mixed Models accommodate nested and hierarchical data structures with random effects

Two-Sample t-Test vs. Advanced Generalizations

A unifying insight is that the two-sample t-test is equivalent to a simple linear regression where the predictor is a binary indicator variable (0 for group 1, 1 for group 2). The regression coefficient equals x̄₂ − x̄₁, and the t-statistic for testing whether that coefficient is zero is identical to the pooled two-sample t-statistic. This equivalence highlights that hypothesis testing and regression are two views of the same underlying linear model, a perspective that becomes increasingly valuable as you progress into multivariable statistics, experimental design, and causal inference.

SECTION 9

Practice Problems

Question 1: CONCEPTUAL

Explain why the two-sample t-test uses the t-distribution rather than the standard normal (z) distribution. Under what conditions would the two distributions yield essentially identical results?
Show answer
The t-distribution is used because the population standard deviations σ₁ and σ₂ are unknown and must be estimated from the sample data using s₁ and s₂. This estimation introduces additional uncertainty beyond that of sampling variability alone, and the t-distribution's heavier tails account for this extra uncertainty. The shape of the t-distribution is governed by the degrees of freedom: as df increases, the t-distribution converges to the standard normal. In practice, when the combined degrees of freedom exceed approximately 120, the critical values from the t- and z-distributions are nearly indistinguishable, so results would be essentially identical.

Question 2: BASIC CALCULATION

Two independent samples are collected. Group A: n₁ = 10, x̄₁ = 45.0, s₁ = 5.0. Group B: n₂ = 10, x̄₂ = 40.0, s₂ = 5.0. Assuming equal variances, compute the pooled standard error, the t-statistic, and the degrees of freedom.
Show answer
First, compute the pooled variance: s²_p = [(10−1)(25) + (10−1)(25)] / (10+10−2) = (225 + 225)/18 = 450/18 = 25. The pooled standard error is SE = √[25 × (1/10 + 1/10)] = √[25 × 0.2] = √5 ≈ 2.236. The test statistic is t = (45 − 40)/2.236 = 5/2.236 ≈ 2.236. The degrees of freedom are df = 10 + 10 − 2 = 18. For a two-tailed test at α = 0.05, the critical value t* ≈ 2.101. Since 2.236 > 2.101, we would reject H₀ and conclude the means differ significantly.

Question 3: INTERMEDIATE

A researcher compares the reaction times (in ms) of participants under two conditions. Condition 1: n₁ = 22, x̄₁ = 312, s₁ = 28. Condition 2: n₂ = 25, x̄₂ = 298, s₂ = 45. Conduct a Welch's t-test at α = 0.05 (two-tailed). Report the test statistic, approximate degrees of freedom, and your conclusion.
Show answer
Compute SE = √(28²/22 + 45²/25) = √(784/22 + 2025/25) = √(35.636 + 81.000) = √116.636 ≈ 10.80. The test statistic is t = (312 − 298)/10.80 = 14/10.80 ≈ 1.296. For Satterthwaite df: numerator = (35.636 + 81.000)² = (116.636)² ≈ 13603.95. Denominator = (35.636)²/21 + (81.000)²/24 = 1269.92/21 + 6561.00/24 = 60.47 + 273.38 = 333.85. So df ≈ 13603.95/333.85 ≈ 40.75. Using df ≈ 40, the two-tailed critical value t* ≈ 2.021. Since |t| = 1.296 < 2.021 (equivalently, p ≈ 0.202 > 0.05), we fail to reject H₀. There is insufficient evidence at the 5% level to conclude that the mean reaction times differ between conditions.

Question 4: APPLIED

A pharmaceutical company is testing whether a new drug lowers systolic blood pressure more than a placebo. The drug group (n₁ = 35) has a mean reduction of x̄₁ = 12.3 mmHg with s₁ = 6.1, and the placebo group (n₂ = 38) has a mean reduction of x̄₂ = 8.7 mmHg with s₂ = 7.4. Set up and carry out a one-tailed t-test at α = 0.01. State your hypotheses, test statistic, p-value, and a conclusion in context.
Show answer
Hypotheses: H₀: μ₁ − μ₂ ≤ 0 (drug does not lower BP more than placebo). H₁: μ₁ − μ₂ > 0 (drug lowers BP more). Using Welch's t-test: SE = √(6.1²/35 + 7.4²/38) = √(37.21/35 + 54.76/38) = √(1.0631 + 1.4411) = √2.5042 ≈ 1.583. t = (12.3 − 8.7)/1.583 = 3.6/1.583 ≈ 2.274. For degrees of freedom: df = (2.5042)²/[(1.0631)²/34 + (1.4411)²/37] = 6.271/[0.03324 + 0.05614] = 6.271/0.08938 ≈ 70.2. Using df ≈ 70, the one-tailed p-value for t = 2.274 is approximately 0.013. Since p = 0.013 > α = 0.01, we fail to reject H₀ at the 1% level. Although there is suggestive evidence of a drug effect, it does not meet the stringent 1% threshold. The company might consider whether a larger sample or the 5% level would be appropriate, and should also consider effect size and clinical significance.

Question 5: CRITICAL THINKING

A colleague conducts a pooled two-sample t-test comparing test scores from two schools. School A has n₁ = 50 students with s₁ = 4, and School B has n₂ = 12 students with s₂ = 15. She reports a significant result at α = 0.05. Critique her approach. Specifically, discuss (a) the validity of the equal-variance assumption, (b) how the unequal sample sizes interact with the variance heterogeneity to affect the Type I error rate, and (c) what alternative she should use.
Show answer
There are several serious concerns. (a) The ratio of variances is s₂²/s₁² = 225/16 ≈ 14.1, which far exceeds any reasonable threshold for assuming equal variances (commonly a ratio below 4). The pooled variance assumption is strongly violated. (b) This scenario is particularly dangerous because the larger sample (n₁ = 50) has the smaller variance and the smaller sample (n₂ = 12) has the larger variance. Under these conditions, the pooled t-test is known to be liberal — its actual Type I error rate exceeds the nominal α, meaning the test rejects too often. This is sometimes called the Behrens–Fisher problem, and the direction of the variance–sample-size pairing matters: the liberal inflation occurs when the smaller group is more variable. (c) She should use Welch's t-test, which does not assume equal variances and adjusts the degrees of freedom via the Satterthwaite approximation. Additionally, with such extreme variance heterogeneity and a small n₂, she should verify normality in School B's data and consider whether a nonparametric test (Mann–Whitney U) or a permutation test might be more appropriate. The significant result from the pooled test cannot be trusted without re-analysis.

SUMMARY

Lesson Summary

Summary

The two-sample t-test provides a principled method for determining whether two population means are significantly different, given data from independent random samples. Under the null hypothesis H₀: μ₁ − μ₂ = 0, the test statistic t measures how many standard errors the observed difference in sample means lies from zero. This statistic follows a t-distribution whose shape is determined by the degrees of freedom. The pooled version assumes equal population variances (df = n₁ + n₂ − 2), while Welch's version relaxes that assumption using the Satterthwaite degrees-of-freedom approximation.

The procedure follows a consistent workflow: state H₀ and H₁, choose the significance level α, verify assumptions (independence, normality, and variance equality), compute the test statistic and p-value, and draw a conclusion in the context of the original research question. Remember that statistical significance does not equal practical significance — always supplement hypothesis tests with confidence intervals and effect-size estimates to communicate the magnitude and precision of the estimated difference.

Varsity Tutors • College Statistics • t-Test for Difference of Means