Inferential Statistics • Lesson 15
Two-Sample t-Test
Learn how to compare the means of two independent groups and determine whether their population means are statistically different.
What You Will Learn
Understand when to use a two-sample t-test.
Distinguish a two-sample test from a one-sample test.
Write hypotheses for comparing two population means.
Understand the difference between independent and paired samples.
Calculate the difference between two sample means.
Interpret the t-statistic and p-value in a real-world context.
What Is a Two-Sample t-Test?
A two-sample t-test is used to compare the means of two independent populations.
Instead of asking whether one population mean equals a fixed number, we ask whether the difference between two population means is consistent with a specified value, usually zero.
Sample mean x̄₁
x̄₁ − x̄₂
Sample mean x̄₂
STEP 1
Start With a Business Question
Suppose an e-commerce company wants to know whether the average order value differs between customers using:
Group A
Customers using the mobile app
Group B
Customers using the website
Research question:
“Is the average order value different between the two groups?”
STEP 2
Write the Hypotheses
NULL HYPOTHESIS
H₀: μ₁ − μ₂ = 0
There is no difference between the two population means.
ALTERNATIVE HYPOTHESIS
Hₐ: μ₁ − μ₂ ≠ 0
The two population means are different.
Directional alternatives are also possible:
Hₐ: μ₁ − μ₂ > 0
Group 1 has a greater mean
Hₐ: μ₁ − μ₂ < 0
Group 1 has a smaller mean
STEP 3
What Does “Two Independent Samples” Mean?
The observations in Group 1 and Group 2 come from separate individuals or units, and one observation is not a matched counterpart of an observation in the other group.
✓ Independent
Comparing spending by randomly selected app users with separately selected website users.
✗ Not independent
Measuring the same customers before and after a campaign.
Important:
When observations are naturally paired, a paired t-test is generally more appropriate. We will study that in Lesson 16.
STEP 4
Compare the Two Sample Means
Difference = x̄₁ − x̄₂
x̄₁
Mean of Group 1
x̄₂
Mean of Group 2
Example:
x̄₁ = ₹2,400
x̄₂ = ₹2,100
Difference = ₹300
STEP 5
The Two-Sample t-Statistic
t = (x̄₁ − x̄₂) / SE
For independent samples, the standard error of the difference depends on the variability and sample size of both groups.
SE(x̄₁ − x̄₂)
= √(s₁²/n₁ + s₂²/n₂)
This is the commonly used Welch two-sample t-test formulation, which does not require the two population variances to be equal.
STEP 6
Worked Example
Suppose we compare average order values for two independent customer groups.
Group 1
n₁ = 25
x̄₁ = ₹2,400
s₁ = ₹500
Group 2
n₂ = 25
x̄₂ = ₹2,100
s₂ = ₹400
Step 1: Difference between means
x̄₁ − x̄₂ = 2400 − 2100
Difference = ₹300
Step 2: Standard error
SE = √(500²/25 + 400²/25)
SE = √(10,000 + 6,400)
SE = √16,400
SE ≈ ₹128.06
Step 3: t-statistic
t = 300 / 128.06
t ≈ 2.34
Interpreting the Difference
A positive difference means Group 1 has a higher sample mean than Group 2. A negative difference means Group 1 has a lower sample mean.
x̄₁ − x̄₂ > 0
Group 1 higher
x̄₁ − x̄₂ = 0
Same sample means
x̄₁ − x̄₂ < 0
Group 1 lower
STEP 7
From t-Statistic to p-value
The t-statistic tells us how many estimated standard errors the observed difference is away from the null value.
We then use the appropriate t-distribution and degrees of freedom to calculate a p-value.
General decision rule:
p ≤ α → Reject H₀
p > α → Fail to reject H₀
STEP 8
Important Assumptions
Independent observations
Observations within and between groups should be independent under the study design.
Quantitative outcome
The variable being compared should be quantitative when testing means.
Reasonable distribution
For small samples, each group's outcome distribution should be reasonably well behaved without severe skewness or extreme outliers.
Unequal variances are allowed
Welch's two-sample t-test does not require equal population variances and is a common default for independent groups.
Independent vs Paired Samples
| Situation | Typical Test | Example |
|---|---|---|
| Separate groups | Two-sample t-test | App users vs website users |
| Same people measured twice | Paired t-test | Before vs after training |
Real-World Analytics
Compare Two Marketing Channels
A company wants to know whether average order value differs between customers acquired through Google Ads and customers acquired through social media advertising.
Google Ads
x̄₁ = ₹2,800
s₁ = ₹600
n₁ = 40
Social Media
x̄₂ = ₹2,500
s₂ = ₹550
n₂ = 40
Difference = 2800 − 2500 = ₹300
The analyst would then calculate the standard error, t-statistic, degrees of freedom, and p-value to evaluate whether the observed difference provides sufficient statistical evidence against H₀.
PRACTICE
Test Your Understanding
CHECK YOUR UNDERSTANDING
What is the main purpose of a two-sample t-test?
CHECK YOUR UNDERSTANDING
For a two-sided comparison of two population means, which null hypothesis is standard?
CHECK YOUR UNDERSTANDING
If x̄₁ = 120 and x̄₂ = 100, what is x̄₁ − x̄₂?
CHECK YOUR UNDERSTANDING
Which situation is most appropriate for an independent two-sample t-test?
CHECK YOUR UNDERSTANDING
What does a positive value of x̄₁ − x̄₂ indicate?
CHECK YOUR UNDERSTANDING
Which method is commonly used when the two independent groups may have unequal variances?
Fill in the Blank
The difference between two sample means can be written as x̄₁ − x̄__.
The null hypothesis commonly states that the difference between population means is ______.
Welch's two-sample t-test does not require the population variances to be ______.
Comparing the same people before and after an intervention is usually a ______ t-test situation.
Analytics Challenge
Compare Two Customer Groups
An analyst compares average monthly spending between two independent customer groups.
Group A
n₁ = 36
x̄₁ = ₹3,000
s₁ = ₹600
Group B
n₂ = 36
x̄₂ = ₹2,700
s₂ = ₹500
Step 1: Difference
3000 − 2700 = ₹300
Step 2: Standard error
SE = √(600²/36 + 500²/36)
SE = √(10,000 + 6,944.44)
SE ≈ ₹126.27
Step 3: t-statistic
t ≈ 300 / 126.27
t ≈ 2.38
Final Challenge
Marketing Campaign Comparison
Campaign A has an average revenue per customer of ₹1,800, while Campaign B has an average of ₹1,650.
What is the observed difference if Campaign A is Group 1?
x̄₁ − x̄₂ = 1800 − 1650
Difference = ₹150
Remember: an observed difference alone does not establish statistical significance. We need the variability, sample sizes, test statistic, and p-value.
Lesson 15 Summary
A two-sample t-test compares the means of two independent populations.
The standard null hypothesis is H₀: μ₁ − μ₂ = 0.
The alternative can be two-sided or directional.
The observed difference is x̄₁ − x̄₂.
The standard error depends on both groups' variability and sample sizes.
Welch's t-test does not require equal population variances.
Independent groups are different from paired observations.
A difference in sample means does not automatically imply statistical significance.
The p-value is used with a pre-specified significance level to make the statistical decision.