Comparing Two Groups
Compare two proportions or two means with confidence intervals and tests, tell paired from independent samples, and meet the chi-square test.
Welcome back!
Step 1 of 13Learn
A/B testing
An online store tests two versions of its checkout page. Version A goes to 2,000 randomly chosen visitors and 200 buy (10%). Version B goes to another 2,000 and 240 buy (12%). Should the store switch to B?
This is an A/B test, a randomized experiment, and the most common form of statistics in the tech industry. The question is the same as before, with a twist: we're comparing two groups. Is the 2-point difference real, or could it come from random variation in who saw which page?
Hypotheses. H₀: p_A = p_B (no difference); Hₐ: p_A ≠ p_B.
Test statistic. Under H₀ both pages share one purchase rate, so we estimate it by pooling: (200 + 240)/4,000 = 0.11. Then
SE = √( 0.11 × 0.89 × (1/2000 + 1/2000) ) ≈ 0.0099 z = (0.12 − 0.10) / 0.0099 ≈ 2.02
The two-sided p-value is about 0.043. At α = 0.05, we reject H₀: there's convincing evidence that the two pages have different purchase rates.
Because visitors were randomly assigned, the store can conclude that the page design caused the difference. A 95% confidence interval for p_B − p_A, roughly 0.001 to 0.039, tells them how big the improvement might be: anywhere from tiny to almost 4 points.
Step 2 of 13Chart
A/B test: checkout conversion rates
200 of 2,000 versus 240 of 2,000. The axis starts at zero so the 2-point gap is not exaggerated. The question for the test: is a gap this size bigger than random assignment alone would produce?
Step 3 of 13Learn
Comparing two means
For quantitative data, compare the two sample means. The standard error of the difference x̄₁ − x̄₂ combines the variability of both samples:
SE = √( s₁²/n₁ + s₂²/n₂ )
Notice the variances add, even though the means are subtracted. Both samples contribute uncertainty, so the difference is more variable than either mean alone.
Two-sample t test. t = (x̄₁ − x̄₂) / SE, with the p-value from a t distribution. (Software computes the exact degrees of freedom; a safe hand rule is to use the smaller of n₁ − 1 and n₂ − 1.)
Example. Forty randomly assigned students used Study Method A and forty used Method B.
- Method A: x̄₁ = 78, s₁ = 10
- Method B: x̄₂ = 73, s₂ = 12
SE = √(100/40 + 144/40) = √(2.5 + 3.6) = √6.1 ≈ 2.47 t = (78 − 73)/2.47 ≈ 2.02, two-sided p-value ≈ 0.047
At α = 0.05 there's convincing, but not overwhelming, evidence that Method A produces higher average scores. A 95% confidence interval for the difference is about 5 ± 2.0 × 2.47, or (0.1, 9.9) points. That wide range shows how uncertain the size of the advantage still is.
The conditions are the same as before, applied to each group: random samples or random assignment, independent groups, and roughly normal data or large samples.
Step 4 of 13Practice · Work it out
Group 1 has s₁ = 10 with n₁ = 25. Group 2 has s₂ = 12 with n₂ = 36. What is the standard error of x̄₁ − x̄₂? Give two decimal places.
Step 5 of 13Learn
Paired data
Not every two-group comparison uses two separate groups. Suppose 12 students take a practice test, attend a review workshop, and take a similar test afterward. Each student gives two measurements. That's paired data.
Paired designs include before-and-after measurements on the same people, twins assigned to different treatments, and comparing two products tested by the same panel of judges.
With paired data, don't use the two-sample method. Instead, compute the difference for each pair (after − before) and analyze those differences as one sample, with a one-sample t test or interval for the mean difference μ_d.
Why pairing helps. Students differ a lot from one another: some score 60, some 95. In a two-sample comparison, that person-to-person variation swamps a modest workshop effect. Pairing compares each student with themselves, so the background differences cancel out. The differences might all be between +2 and +8 points, a clear signal that would be lost in a two-sample analysis.
Example. The 12 differences have mean d̄ = 4.5 points and s_d = 3.0. SE = 3.0/√12 ≈ 0.87, so t = 4.5/0.87 ≈ 5.2, with df = 11. The p-value is far below 0.01: strong evidence the workshop group improved.
But without a control group, the improvement could also come from practice alone. Pairing reduces noise; it doesn't replace random assignment and comparison.
Step 6 of 13Practice · Sort into groups
Is each study paired or two independent samples?
Tap an item, then tap its group (or drag it there).
Step 7 of 13Learn
Categorical variables: the chi-square test
What if both variables are categorical with more than two categories? Suppose a survey asks 400 adults their age group and their preferred news source (TV, websites, social media, print). Is news source related to age?
The chi-square (χ²) test of independence compares the counts we observed in each cell of the two-way table with the counts we'd expect if the variables were unrelated.
Expected count for any cell = (row total × column total) / grand total.
If 150 people are under 30 and 100 people prefer social media, then with no relationship we'd expect 150 × 100 / 400 = 37.5 under-30 social media fans. If we actually observed 65, that cell contributes to evidence of a relationship.
The test statistic adds up the squared gaps, scaled by the expected counts:
χ² = Σ (Observed − Expected)² / Expected
A large χ² means the observed table is far from "no relationship," giving a small p-value from the chi-square distribution with df = (rows − 1)(columns − 1).
A goodness-of-fit version compares one categorical variable to a claimed distribution. Is a die fair? Roll it 120 times: you'd expect 20 of each face. Large deviations give a large χ².
Condition: all expected counts should be at least 5.
Step 8 of 13Practice · Chart
Observed vs. expected: under-30 adults by news source
Tap the news source with the biggest gap between observed and expected.
Tap the bar that answers the question, then press Check.
Step 9 of 13Practice · Work it out
In a two-way table with 400 people, a row has a total of 150 and a column has a total of 200. If the two variables were independent, what is the expected count for the cell where they meet?
Step 10 of 13Practice · Match the pairs
Match each research question to the most suitable procedure.
Tap an answer, then tap the place where it belongs (or drag it there).
- Do a larger share of visitors buy with page B than with page A?
- Do two randomly assigned diets lead to different mean weight loss?
- Did 25 workers type faster after a training course than before it?
- Is preferred music genre related to region of the country?
- What is the mean commute time of all residents of a city?
Step 11 of 13Practice · Diagram
Choosing a two-group procedure
Ten runners are timed before and after a training plan. Which branch fits?
Tap the shape that answers the question, then press Check.
- What kind of response?
- Quantitative
- Categorical
- Two separate groups
Two-sample t: SE = √(s₁²/n₁ + s₂²/n₂).
- Paired measurements
Compute each pair's difference, then a one-sample t on the differences.
- Two proportions
Two-proportion z, as in an A/B test.
- Several categories
Chi-square test of independence on the two-way table.
Step 12 of 13Note
Step 13 of 13Practice · Choose one
A 95% confidence interval for the difference in mean recovery time (new treatment minus standard) is (−1.2, 4.8) days. What should you conclude?
Lesson complete!