Two-Sample Hypothesis Tests

1

Two-Sample Hypothesis Tests

When researchers want to know whether two distinct populations differ on some measurable characteristic, they turn to two-sample hypothesis tests. Unlike a one-sample test — which compares a single sample mean to a known or hypothesized population value — a two-sample test compares statistics from two separate groups to determine whether any observed difference is likely real or merely the product of random sampling variation. This framework appears constantly in practice: a pharmaceutical company comparing a drug to a placebo, an educator comparing test scores from two teaching methods, or a manufacturer comparing defect rates from two production lines. Understanding the logic, assumptions, and mechanics of these tests is therefore fundamental to applied statistical reasoning.

Logic of Two-Sample Hypothesis Testing

The starting point for any hypothesis test is a pair of competing claims about the populations of interest. In a two-sample context, the null hypothesis (H₀) almost always asserts that there is no meaningful difference between the two population parameters being compared. For means, this is written as H₀: μ₁ = μ₂, or equivalently H₀: μ₁ − μ₂ = 0. The alternative hypothesis (H₁) asserts that a difference does exist. Depending on the research question, H₁ can take three forms:

  • Two-tailed: H₁: μ₁ ≠ μ₂ — used when the researcher has no prior expectation about which group will be larger.
  • Left-tailed: H₁: μ₁ < μ₂ — used when the researcher specifically expects group 1 to have a smaller mean.
  • Right-tailed: H₁: μ₁ > μ₂ — used when the researcher specifically expects group 1 to have a larger mean.

The core logic of the test is a proof by contradiction: assume the null hypothesis is true, then compute the probability of observing a difference between sample statistics as large as (or larger than) the one actually observed. This probability is the p-value. If the p-value is very small, the data are hard to explain under H₀, which is taken as evidence against it. If the p-value is large, the observed difference is consistent with ordinary sampling variation and does not constitute strong evidence against H₀.

For example, suppose Group A has a sample mean of 105 and Group B has a sample mean of 100. The question is not simply "are these numbers different?" — they obviously are. The question is: how surprising is a difference of 5 points if the two populations truly have the same mean? The hypothesis testing procedure answers exactly that question by placing the observed difference on a standardized scale and determining where it falls relative to a known probability distribution.

Independence Assumption and Sampling

Before any calculations begin, the study design must satisfy the independence assumption. This requirement has two distinct layers, both of which must hold.

  • Between-group independence: The two samples must be drawn independently from their respective populations. Knowing which individuals ended up in Group 1 should give no information about who ended up in Group 2. This is typically satisfied when participants are randomly assigned to conditions (as in a controlled experiment) or when two entirely separate populations are sampled (e.g., students from two different schools).
  • Within-group independence: Observations within each sample must also be independent of one another. If one observation's value influences another — for instance, because participants share a classroom, are related, or are measured repeatedly — the independence assumption is violated.

Violating independence has serious consequences. When observations are correlated, the effective sample size is smaller than the nominal sample size, so the standard error is underestimated. This makes the test statistic artificially large and inflates the Type I error rate (the probability of falsely rejecting a true null hypothesis) well above the nominal α level. In clustered data (e.g., students nested within classrooms), the appropriate remedy is often a mixed-effects model or a cluster-robust standard error, not a standard two-sample test.

When independence cannot be guaranteed — for instance, when the same individuals are measured under two different conditions — the correct approach is a paired test, which accounts for the within-subject correlation. The two-sample tests described here apply strictly to independent groups.

Two-Sample Z-Test

The two-sample z-test is appropriate when both population standard deviations (σ₁ and σ₂) are known, or when both sample sizes are large enough (conventionally n ≥ 30 for each group) that the sample standard deviations are reliable estimates and the Central Limit Theorem ensures approximate normality of the sampling distribution of the difference in means.

The test statistic is computed as:

z = (x̄₁ − x̄₂) − (μ₁ − μ₂)₀
    ─────────────────────────────
         SE(x̄₁ − x̄₂)

where (μ₁ − μ₂)₀ is the hypothesized difference under H₀ (usually 0), and the standard error of the difference is:

SE = √(σ₁²/n₁ + σ₂²/n₂)

This formula reflects an important principle: the variance of the difference between two independent random variables equals the sum of their individual variances. Each sample mean has variance σ²/n, so the difference in sample means has variance σ₁²/n₁ + σ₂²/n₂, and the standard error is the square root of that sum.

The resulting z-score is compared to critical values from the standard normal distribution. For a two-tailed test at α = 0.05, the critical values are ±1.96; any |z| > 1.96 leads to rejection of H₀. For a one-tailed test at α = 0.05, the critical value is 1.645.

Worked example: A nutritionist measures the daily caloric intake of two independent groups. Group 1 (n₁ = 50) has x̄₁ = 2,150 kcal with known σ₁ = 300 kcal. Group 2 (n₂ = 60) has x̄₂ = 2,050 kcal with known σ₂ = 280 kcal. Testing H₀: μ₁ − μ₂ = 0 versus H₁: μ₁ ≠ μ₂ at α = 0.05:

SE = √(300²/50 + 280²/60)
   = √(90000/50 + 78400/60)
   = √(1800 + 1306.67)
   = √3106.67
   ≈ 55.74

z = (2150 − 2050) / 55.74
  = 100 / 55.74
  ≈ 1.794

Since |1.794| < 1.96, we fail to reject H₀ at the 5% significance level. The observed 100 kcal difference is not statistically significant.

Two-Sample T-Test

In most real-world scenarios, population standard deviations are unknown and must be estimated from the data. The two-sample t-test replaces the known σ values with sample standard deviations and uses the t-distribution rather than the normal distribution to account for the additional uncertainty introduced by estimation. There are two variants, and choosing between them depends on whether the population variances can be assumed equal.

Pooled (Equal-Variance) T-Test

When it is reasonable to assume σ₁² = σ₂², both samples' information can be combined into a single pooled variance estimate, which is a weighted average of the two sample variances weighted by their degrees of freedom:

sp² = [(n₁ − 1)s₁² + (n₂ − 1)s₂²] / (n₁ + n₂ − 2)

The test statistic is then:

t = (x̄₁ − x̄₂) / √(sp²(1/n₁ + 1/n₂))

This t-statistic follows a t-distribution with df = n₁ + n₂ − 2 degrees of freedom under H₀. Pooling is advantageous because it produces a more precise (lower variance) estimate of the common population variance by using all available data.

Welch's (Unequal-Variance) T-Test

When the assumption of equal variances is not warranted — which is the more common situation in practice — Welch's t-test is used. It does not pool the variances and instead computes the standard error directly from each sample's own variance:

t = (x̄₁ − x̄₂) / √(s₁²/n₁ + s₂²/n₂)

The numerator is identical to the pooled test, but the denominator differs. More importantly, Welch's test uses an adjusted degrees of freedom computed by the Welch–Satterthwaite equation:

df = (s₁²/n₁ + s₂²/n₂)²
     ───────────────────────────────────────────
     (s₁²/n₁)²/(n₁−1)  +  (s₂²/n₂)²/(n₂−1)

This formula produces a non-integer degrees of freedom value, which is then used to look up the critical value or p-value from the t-distribution. The result is generally a more conservative test (slightly wider critical region) than the pooled test when variances truly are unequal, protecting against inflated Type I errors.

Because Welch's test performs nearly as well as the pooled test when variances are equal, and much better when they are not, Welch's t-test is recommended as the default two-sample t-test in most modern statistical practice. Many statistical software packages (including R's t.test() function) use Welch's test by default.

Worked example for Welch's t-test: Two independent classes take the same exam. Class A (n₁ = 20): x̄₁ = 78, s₁ = 12. Class B (n₂ = 25): x̄₂ = 72, s₂ = 8. Testing H₀: μ₁ = μ₂ vs. H₁: μ₁ ≠ μ₂ at α = 0.05:

SE = √(12²/20 + 8²/25)
   = √(144/20 + 64/25)
   = √(7.2 + 2.56)
   = √9.76
   ≈ 3.124

t = (78 − 72) / 3.124 = 6 / 3.124 ≈ 1.921

Numerator of df: (7.2 + 2.56)² = 9.76² = 95.258
Denominator: (7.2)²/19 + (2.56)²/24
           = 51.84/19 + 6.5536/24
           = 2.728 + 0.273 = 3.001

df ≈ 95.258 / 3.001 ≈ 31.74  →  use df ≈ 31

At df = 31, the two-tailed critical value at α = 0.05 is approximately 2.040. Since |1.921| < 2.040, we fail to reject H₀. The difference is not statistically significant at the 5% level (though it is close, which would be worth noting alongside the effect size).

Assumptions Underlying Two-Sample Tests

The validity of two-sample z-tests and t-tests rests on a set of assumptions. Violations of these assumptions can compromise the reliability of conclusions.

  • Random and independent sampling: Both samples should be drawn randomly from their respective populations. Random sampling ensures that the samples are representative and that the sampling distributions behave as the theory predicts. As discussed, independence within and between groups is non-negotiable.
  • Approximate normality: The data within each group should be approximately normally distributed. For large samples (each n ≥ 30), the Central Limit Theorem ensures that the sampling distribution of the mean is approximately normal regardless of the shape of the underlying data distribution, making this assumption less critical. For small samples, the original data should be checked for severe skewness or outliers using histograms, Q-Q plots, or formal normality tests (e.g., Shapiro-Wilk). If normality is seriously violated in small samples, non-parametric alternatives such as the Mann-Whitney U test should be considered.
  • Equal variances (for the pooled t-test only): The pooled t-test requires that σ₁² = σ₂². This can be assessed using Levene's test (which tests for equality of variances and is robust to non-normality) or the F-test (which directly tests the ratio of the two sample variances but is sensitive to departures from normality). If there is evidence that variances are unequal, Welch's t-test should be used instead.

The table below summarizes when to use each test:

Situation Appropriate Test Degrees of Freedom
σ₁ and σ₂ known (or n₁, n₂ both large) Two-sample Z-test Not applicable (use z-table)
σ₁, σ₂ unknown; equal variances reasonable Pooled two-sample t-test n₁ + n₂ − 2
σ₁, σ₂ unknown; variances differ or unknown Welch's two-sample t-test Welch–Satterthwaite approximation
Non-normal data, small samples Mann-Whitney U (non-parametric) Not applicable

Interpreting Results and Making Decisions

Once the test statistic and p-value have been computed, the decision rule is straightforward: if the p-value is less than the pre-specified significance level α (commonly 0.05 or 0.01), the null hypothesis is rejected in favor of the alternative. This is described as a "statistically significant" result. If the p-value ≥ α, the null hypothesis is not rejected — note that this is not the same as proving H₀ is true; it simply means the data do not provide sufficient evidence to reject it.

However, statistical significance alone tells an incomplete story. Several additional elements should always accompany the reporting of a two-sample test:

  • Direction and magnitude of the difference: Report the actual observed difference (x̄₁ − x̄₂) and its sign. A statistically significant result that ignores whether Group 1 was higher or lower than Group 2 is poorly communicated. The effect size (e.g., Cohen's d = (x̄₁ − x̄₂) / sp) provides a standardized measure of practical importance, independent of sample size.
  • Confidence interval for the difference: A confidence interval (CI) for μ₁ − μ₂ provides a range of plausible values for the true population difference, directly complementing the hypothesis test. For a two-sample t-test, the 95% CI is:
    (x̄₁ − x̄₂) ± t* × SE
    where t* is the critical value from the t-distribution at the appropriate degrees of freedom. If this interval excludes 0, the result is significant at the 5% level — completely consistent with the p-value decision. The CI also reveals whether the difference is large enough to be practically meaningful: a significant result with a CI of (0.001, 0.003) may be statistically real but practically negligible.
  • Practical significance: A large sample size can render even tiny, unimportant differences statistically significant. Always ask whether the magnitude of the difference matters in the real-world context of the study, not just whether it exceeds a statistical threshold.

Putting all these elements together, a complete and responsible reporting of a two-sample test might read: "Participants in the intervention group (M = 78.0, SD = 12.0, n = 20) scored higher on average than those in the control group (M = 72.0, SD = 8.0, n = 25); however, this 6-point difference was not statistically significant using Welch's t-test, t(31.74) = 1.921, p = .064. The 95% confidence interval for the true difference ranged from −0.37 to 12.37 points, suggesting meaningful uncertainty about the population effect." This kind of reporting gives readers everything they need to evaluate the finding for themselves.

NotesThe worked examples use round numbers for pedagogical clarity. Instructors may wish to supplement with data-driven exercises using real datasets to reinforce the connection between formula mechanics and software output (e.g., R, Python, SPSS). The Mann-Whitney U test is mentioned as a non-parametric alternative but is not developed here; it may warrant its own topic if the module covers non-parametric methods.