Two-Sample Independent Student’s t-Test: Theory, Computation, and Interpretation

by Rao Statistics · Last updated on 1 Nov 2026 · 3.1 Two-Sample t-Test

A complete step-by-step mathematical derivation and parallel software demonstration in R, Python, and Excel

Learning Objective

By the end of this lesson: Formulate hypotheses, calculate the pooled variance and t-statistic for two independent samples with equal population variances, compute exact p-values, and articulate a defensible statistical conclusion.

Statistical Theory & Assumptions

The independent two-sample t-test evaluates whether the difference between two sample means is statistically distinguishable from zero. Under the null hypothesis H0:μ1−μ2=0,H_0: \mu_1 - \mu_2 = 0\text{,} assuming both populations are normally distributed with equal variance σ2,\sigma^2\text{,} the test statistic follows a Student’s t-distribution with (n1+n2−2)(n_1 + n_2 - 2) degrees of freedom.

Assumptions

  • Continuous Scale: The dependent outcome variable is measured on an interval or ratio scale.
  • Independence: Observations within and between both groups are randomly sampled and mutually independent.
  • Normality: Both populations follow approximately normal distributions (verifiable via Shapiro-Wilk test or Q-Q plot).
  • Homoscedasticity: Population variances are equal (σ12=σ22,\text{(}\sigma_1^2 = \sigma_2^2\text{,} verifiable via Levene’s or Bartlett’s test).
t=xˉ1−xˉ2sp1n1+1n2,sp=(n1−1)s12+(n2−1)s22n1+n2−2t = \frac{\bar{x}_1 - \bar{x}_2}{s_p \sqrt{\frac{1}{n_1} + \frac{1}{n_2}}}, \quad s_p = \sqrt{\frac{(n_1 - 1)s_1^2 + (n_2 - 1)s_2^2}{n_1 + n_2 - 2}}

Where sps_p is the pooled sample standard deviation, defined as sp=(n1−1)s12+(n2−1)s22n1+n2−2,s_p = \sqrt{\frac{(n_1 - 1)s_1^2 + (n_2 - 1)s_2^2}{n_1 + n_2 - 2}}\text{,} and degrees of freedom ν=n1+n2−2.\nu = n_1 + n_2 - 2\text{.}

Worked Dataset & Variables

Instructional Method Examination Scores: Comparison of final assessment scores (out of 100) between undergraduate students enrolled in interactive problem-solving laboratory (Cohort A) versus traditional lecture instruction (Cohort B). (sample size n = 24).

Data dictionary
VariableTypeDescription
student_idIntegerUnique anonymized identifier
cohortFactorInstructional group: Cohort A (Interactive) or Cohort B (Traditional)
exam_scoreNumericFinal standardized score (0–100 scale)
Sample observations
student_idcohortexam_score
101Cohort A84.5
102Cohort A79
103Cohort A88
104Cohort A82.5
105Cohort A91
106Cohort A76.5
107Cohort A85
108Cohort A89.5
109Cohort A81
110Cohort A87.5
111Cohort A93
112Cohort A83.5
201Cohort B74
202Cohort B78.5
203Cohort B71
204Cohort B75.5
205Cohort B80
206Cohort B72.5
207Cohort B76
208Cohort B79.5
209Cohort B69
210Cohort B77
211Cohort B73.5
212Cohort B75

Software Procedure (R, Python & Excel)

# Load dataset and inspect summary metrics
data <- read.csv("exam_scores_cohort.csv")

# Compute summary statistics by group
aggregate(exam_score ~ cohort, data = data, FUN = function(x) c(mean = mean(x), sd = sd(x), n = length(x)))

# Test equality of variances (Levene's Test)
# car::leveneTest(exam_score ~ cohort, data = data)

# Run Independent Two-Sample Student's t-test with pooled variance
test_result <- t.test(exam_score ~ cohort, data = data, var.equal = TRUE, conf.level = 0.95)
print(test_result)

Numerical Results

The computation reveals a pronounced difference between the two instructional cohorts. The sample mean for Cohort A is 85.08 (SD = 4.88, n = 12), compared to 75.13 (SD = 3.42, n = 12) for Cohort B.

Key results
StatisticValueNote
Sample Mean Cohort A (x̄₁)85.08Interactive Laboratory
Sample Mean Cohort B (x̄₂)75.13Traditional Lecture
Mean Difference (x̄₁ - x̄₂)+9.95Score advantage
Pooled Standard Deviation (sp)\text{(}s_p\text{)}4.22Common variance estimate
Degrees of Freedom (df)22n1+n2−2n_1 + n_2 - 2
Observed t-statistic5.78Critical value t0.05/2=2.074t_{0.05/2} = 2.074
p-value (two-tailed)4.92×10−64.92 \times 10^{-6}Extremely statistically significant
95% Confidence Interval for (μ1−μ2)(\mu_1 - \mu_2)[6.38, 13.52]Excludes zero

Interpretation & Decision Rule

Formal conclusion: At the α=0.05\alpha = 0.05 significance level, we reject the null hypothesis H0:μ1=μ2H_0: \mu_1 = \mu_2 (t(22)=5.78,\text{(}t(22) = 5.78\text{,} p<0.001).p < 0.001\text{).} The 95% confidence interval for the true population mean difference spans from 6.38 to 13.52 score points.

Decision rule: Since the observed ∣t∣=5.78|t| = 5.78 substantially exceeds the critical threshold tcrit=2.074,t_{\text{crit}} = 2.074\text{,} and the two-sided p-value is strictly less than α=0.05,\alpha = 0.05\text{,} the evidence against H0H_0 is decisive.

Practical significance: The interactive problem-solving laboratory method yielded an estimated average improvement of nearly 10 points over traditional lecture instruction. Given that the confidence interval does not contain zero, educators can conclude that the performance enhancement is both statistically reproducible and practically meaningful.

Check Variance Homogeneity First: If Levene’s test yields p<0.05,p < 0.05\text{,} equal variance cannot be safely assumed. In that case, use Welch’s t-test (var.equal = FALSE in R, equal_var=False in Python), which applies Satterthwaite’s approximation for degrees of freedom.

Robustness to Normality Departures: The two-sample Student’s t-test is relatively robust to moderate departures from normality when sample sizes are equal (n1=n2)\text{(}n_1 = n_2\text{)} due to the Central Limit Theorem. However, for severe skewness or small samples, consider the Mann-Whitney U test.

Practice Files

Download: two_sample_ttest_exam_cohorts.csv (CSV Dataset, 1.2 KB)

You might also like

← 3.1 Two-Sample t-Test