Two Sample Mean Test

A Two Sample Mean Test (commonly called an independent samples t-test) checks whether the means of two independent groups are significantly different from each other - for example, comparing average test scores between two different teaching methods.

When to Use It

Use this test when you have two separate, unrelated groups and want to know if a numeric variable's average genuinely differs between them, rather than the difference being due to random sampling variation.

Setting Up the Hypotheses

# H0: The two group means are equal (no real difference)
# H1: The two group means are not equal (there is a real difference)

Running the Test in Python

from scipy import stats
import numpy as np

method_a_scores = np.array([72, 75, 78, 74, 71, 76])
method_b_scores = np.array([80, 83, 79, 85, 82, 81])

t_stat, p_value = stats.ttest_ind(method_a_scores, method_b_scores)
print("T-statistic:", t_stat)
print("P-value:", p_value)

alpha = 0.05
if p_value < alpha:
    print("Reject H0 - the two methods differ significantly")
else:
    print("Fail to reject H0 - no significant difference found")

Equal vs Unequal Variance

By default, many implementations assume the two groups have equal variance. If that's not a safe assumption, Welch's t-test (equal_var=False in SciPy) is a more robust choice.

A statistically significant result tells you the difference is unlikely due to chance, but it's still worth checking the actual size of the difference (the effect size) to judge whether it's practically meaningful too.

Coming Up Next

Next, you'll learn the Proportion Test - used for comparing percentages or rates instead of means.

Ready to Master Data Science?

Join Uncodemy's Data Science Course and build real, job-ready skills with expert mentors.

Explore Course