Instant PDF download, name-and-email checkout. Complete bundle: every Economics and Statistics book
Statistics guide, Unit 4, step 18 of 22Previous stepNext step

Step 18: Comparing Two Groups

SyllabusAP Stats 4.6–4.10
In 30 seconds
  • When you compare two groups, the thing you estimate is a difference: \( \mu_1 – \mu_2 \) for means, or \( p_1 – p_2 \) for proportions. The key question is always: is zero a plausible value for that difference?
  • Check the design first. Independent samples are two separate groups of people; paired samples link each value in one group to a partner in the other (often the same person measured twice).
  • Independent means use \( SE = \sqrt{s_1^2/n_1 + s_2^2/n_2} \) with df = smaller \( n – 1 \). Paired data is turned into one list of differences and analysed with one-sample methods. Two proportions use a pooled SE for the test and an unpooled SE for the interval.
  • Exam point: an interval for the difference that contains 0 means “no significant difference”; one that excludes 0 means “significant”. Always report the interval, not just the p-value.
Video lesson coming soonA short animated lesson for this step will appear here.

Why comparing two groups is about a difference

Imagine a company tests two versions of a web page. Version A is shown to 1,000 visitors and 110 of them buy something (11%). Version B is shown to a different 1,000 visitors and 140 buy (14%). The team is excited: B looks 27% better. Someone starts writing the announcement.

But hold on. Even if the two pages were exactly as good as each other, two random groups of visitors would not behave identically. Some gap would appear just by chance. So the real question is: how often would chance alone produce a gap as big as 3 percentage points?

Most practical questions in statistics are like this: two groups, and what you care about is the difference between them. The strategy is familiar. Estimate \( \mu_1 – \mu_2 \) with \( \bar{x}_1 – \bar{x}_2 \), find that estimate’s standard error, and then use the familiar interval and test machinery.

Key termDifference of means: the parameter \( \mu_1 – \mu_2 \), estimated from the samples by \( \bar{x}_1 – \bar{x}_2 \).

Here is the single idea that ties the whole step together. The null hypothesis is almost always “no difference”, which in symbols is \( \mu_1 – \mu_2 = 0 \). So everything reduces to one question: is zero a believable value for the difference? If a confidence interval for the difference contains zero, the groups are not significantly different. If it excludes zero, they are.

Independent or paired? Decide before you calculate

Two different procedures exist, and using the wrong one gives wrong answers. So the very first job is to identify the design.

  • Independent samples are two separate, unrelated groups: 40 patients given a drug and a different 40 given a placebo. A value in one group tells you nothing about any particular value in the other. The groups need not be the same size.
  • Paired samples link each observation in one group to a specific observation in the other. The most common case is measuring the same person twice (before and after a course). Another is deliberately matching people into pairs, for example twins or students of similar ability. The sample sizes must be equal.
Key termPaired samples: two sets of measurements in which every value has a natural partner in the other set, such as the same student’s score before and after training.

One question settles it: does each value in group 1 have a natural partner in group 2? If yes, the design is paired. If no, it is independent.

Common mistakeRunning a two-sample test on paired data throws the pairing away. The big differences between people then swamp the effect, and you may find nothing. Running a paired test on independent data is worse: it is simply invalid, because there are no real pairs to subtract.

Two means from independent samples

For two separate groups, the difference \( \bar{x}_1 – \bar{x}_2 \) estimates \( \mu_1 – \mu_2 \). Its standard error combines the variability of both groups. Notice something surprising: the means are subtracted, but the variances add. That is because each group brings its own uncertainty, and subtracting does not cancel uncertainty out.

\[ SE = \sqrt{\frac{s_1^2}{n_1} + \frac{s_2^2}{n_2}} \qquad \text{interval: } (\bar{x}_1 – \bar{x}_2) \pm t^{*} \cdot SE \qquad \text{test: } t = \frac{\bar{x}_1 – \bar{x}_2}{SE} \]

The exact degrees of freedom for this test come from a complicated formula that software works out. By hand, the book uses a conservative rule: df = (smaller sample size) − 1. This gives a slightly wider interval, which errs on the side of caution.

Conditions: both samples are random and independent of each other, and each group is either roughly normal or has at least 30 observations.

Worked example

Two teaching methods are compared. Method B: \( n = 36,\ \bar{x} = 78,\ s = 9 \). Method A: \( n = 36,\ \bar{x} = 72,\ s = 8 \). Build a 95% interval for \( \mu_B – \mu_A \) and test whether the methods differ at \( \alpha = 0.05 \).

Step 1Observed difference: \( 78 – 72 = 6 \) points.
Step 2\( SE = \sqrt{81/36 + 64/36} = \sqrt{2.25 + 1.778} = \sqrt{4.028} = 2.007 \)
Step 3df = 36 − 1 = 35, so \( t^{*} = 2.030 \). Margin: \( 2.030 \times 2.007 = 4.07 \). Interval: \( 6 \pm 4.07 = (1.93,\ 10.07) \).
Step 4Test: \( t = 6 \div 2.007 = 2.99 \) with df = 35, two-tailed p ≈ 0.005.

We are 95% confident that method B’s true mean is between about 1.9 and 10.1 points higher than method A’s. The interval excludes zero and p < 0.05, so the difference is significant. The interval and the test agree, as they always must. But notice how wide the interval is: the true advantage could be a modest 2 points or a large 10.

Two means from paired samples

Paired data has a neat shortcut. For each pair, work out the difference, \( d = \text{after} – \text{before} \). Then throw away the original two columns. You are left with one list of differences, and you analyse it with the one-sample methods you already know.

\[ t = \frac{\bar{d}}{s_d / \sqrt{n}} \qquad \bar{d} \pm t^{*} \cdot \frac{s_d}{\sqrt{n}} \qquad \text{df} = n – 1 \]

Here \( \bar{d} \) and \( s_d \) are the mean and standard deviation of the differences, and \( n \) is the number of pairs, not the total number of measurements.

Worked example

Sixteen students sit a test before and after a training course. The differences (after − before) have \( \bar{d} = 5.0 \) points and \( s_d = 4.0 \) points. Does the course improve scores? Use \( \alpha = 0.05 \) and give a 95% interval.

Step 1\( H_0: \mu_d = 0 \), \( H_a: \mu_d \gt 0 \), where \( \mu_d \) is the true mean improvement.
Step 2\( SE = 4.0 \div \sqrt{16} = 1.0 \), so \( t = 5.0 \div 1.0 = 5.00 \) with df = 15. One-tailed p is under 0.001.
Step 3\( t^{*} = 2.131 \): \( 5.0 \pm 2.131(1.0) = (2.87,\ 7.13) \) points.

Reject \( H_0 \): there is very strong evidence the course raises scores, by somewhere between about 2.9 and 7.1 points on average.

Why does pairing work so well? The students’ scores might range from 40 to 95, but their improvements cluster tightly around 5. That small spread makes the standard error small and t large. When you can pair, pair.

Comparing two proportions

The logic for proportions is the same, with one twist: the interval and the test use different standard errors.

For the interval, each group uses its own sample proportion:

\[ (\hat{p}_1 – \hat{p}_2) \pm z^{*} \sqrt{\frac{\hat{p}_1(1-\hat{p}_1)}{n_1} + \frac{\hat{p}_2(1-\hat{p}_2)}{n_2}} \]

For the test, \( H_0 \) says the two proportions are equal. If they are equal, the best estimate of that shared value combines all the data. This is the pooled proportion:

\[ \hat{p}_{pool} = \frac{x_1 + x_2}{n_1 + n_2} \qquad z = \frac{\hat{p}_1 – \hat{p}_2}{\sqrt{\hat{p}_{pool}(1-\hat{p}_{pool})\left(\frac{1}{n_1} + \frac{1}{n_2}\right)}} \]

Conditions: both samples random and independent, with at least 10 successes and 10 failures in each group.

Key termPooled proportion: the overall success rate of both groups combined, \( (x_1 + x_2) \div (n_1 + n_2) \), used only in the test because \( H_0 \) assumes the proportions are equal.
Worked example

Back to the web pages. Version B converts 140 of 1,000 visitors; version A converts 110 of 1,000. Test at \( \alpha = 0.05 \) whether the rates differ, and give a 95% interval.

Step 1\( \hat{p}_B = 0.14 \), \( \hat{p}_A = 0.11 \), difference 0.03. Successes/failures 140/860 and 110/890, all above 10.
Step 2\( \hat{p}_{pool} = 250 \div 2000 = 0.125 \). \( SE = \sqrt{0.125 \times 0.875 \times (2/1000)} = 0.01479 \).
Step 3\( z = 0.03 \div 0.01479 = 2.03 \), two-tailed p ≈ 0.043.
Step 4Unpooled \( SE = \sqrt{0.14(0.86)/1000 + 0.11(0.89)/1000} = 0.01477 \). Margin \( 1.96 \times 0.01477 = 0.029 \). Interval: \( (0.001,\ 0.059) \).

Since 0.043 < 0.05, B converts at a significantly higher rate. But the interval tells the fuller story: the true gain could be anything from 0.1 to 5.9 percentage points. B is probably better, but the data cannot say whether the gain is tiny or worthwhile. The announcement was premature.

Common mistakeTwo habits ruin A/B tests. Peeking: checking repeatedly and stopping the moment p dips below 0.05 pushes the false-positive rate far above 5%. Fix the sample size in advance and test once. And quoting only the relative change: “27% better” sounds decisive, but here it is 3 percentage points with an interval from 0.1 to 5.9. Always report the absolute difference and its interval.

Reading the interval and test together, and choosing the procedure

Because the null value for a difference is zero, you can read the test result straight from a 95% interval:

If the 95% interval for the difference…Then at \( \alpha = 0.05 \)…Report
contains 0fail to reject \( H_0 \)No significant difference detected
lies entirely above 0reject \( H_0 \)Group 1 significantly higher
lies entirely below 0reject \( H_0 \)Group 1 significantly lower
excludes 0, but only justreject \( H_0 \)Significant, but the size is poorly pinned down

By this stage of a course, the most common exam error is not arithmetic. It is choosing the wrong test. Two questions settle it: what kind of data is it, and how were the groups formed?

DataDesignProceduredf
QuantitativeOne group vs a claimed valueOne-sample t\( n – 1 \)
QuantitativeTwo separate groupsTwo-sample tsmaller \( n – 1 \)
QuantitativeSame or matched subjects twicePaired t on the differencespairs − 1
CategoricalOne group vs a claimed valueOne-proportion znone
CategoricalTwo separate groupsTwo-proportion z (pooled)none
Exam tipMarks come from four things: naming the design (independent or paired) with a reason, checking the conditions, using the right standard error (pooled for the proportion test, unpooled for the interval), and concluding in context. Say whether the interval contains zero and what that means, and comment on how wide it is.

Practise: 6 questions

Try each one on paper first, then check the worked answer.

EasyQ1. Independent or paired? (a) Blood pressure of 30 patients before and after a drug. (b) Salaries of 50 graduates from university X and 60 from university Y. (c) Left-hand and right-hand grip strength of 25 people. Show worked answer
(a) Paired: the same patients are measured twice.
(b) Independent: different people, and the groups are even different sizes.
(c) Paired: two measurements on the same person, so each left-hand value has a natural right-hand partner.
EasyQ2. Group 1: \( n = 25,\ \bar{x} = 52,\ s = 6 \). Group 2: \( n = 25,\ \bar{x} = 48,\ s = 8 \). Find the standard error of the difference and the t statistic. Show worked answer
\( SE = \sqrt{36/25 + 64/25} = \sqrt{1.44 + 2.56} = \sqrt{4} = 2.0 \)
Difference \( = 52 – 48 = 4 \)
\( t = 4 \div 2.0 = 2.00 \), with conservative df = 25 − 1 = 24.
MediumQ3. Using Q2 and \( t^{*} = 2.064 \), build the 95% interval for \( \mu_1 – \mu_2 \). Is the difference significant? Show worked answer
Margin \( = 2.064 \times 2.0 = 4.13 \)
Interval \( = 4 \pm 4.13 = (-0.13,\ 8.13) \)
The interval contains zero, so the difference is not significant at the 5% level. Zero is a plausible value for the true difference.
MediumQ4. In a paired study of 25 people, the differences have \( \bar{d} = 3 \) and \( s_d = 5 \). Find the SE, t and df, then build a 95% interval using \( t^{*} = 2.064 \). Show worked answer
\( SE = 5 \div \sqrt{25} = 1.0 \)
\( t = 3 \div 1.0 = 3.00 \), df = 25 − 1 = 24
Interval \( = 3 \pm 2.064(1.0) = (0.94,\ 5.06) \)
Zero is excluded, so the mean difference is significantly different from zero.
MediumQ5. A retailer tests a new checkout page. Old page: 220 purchases from 2,000 visitors. New page: 260 from 2,000. Compute the pooled proportion and z for a two-sided test. Show worked answer
\( \hat{p}_{old} = 220/2000 = 0.11 \), \( \hat{p}_{new} = 260/2000 = 0.13 \), difference 0.02
Conditions: 220/1,780 and 260/1,740 successes/failures, all above 10.
\( \hat{p}_{pool} = 480 \div 4000 = 0.12 \)
\( SE = \sqrt{0.12 \times 0.88 \times (2/2000)} = \sqrt{0.0001056} = 0.01028 \)
\( z = 0.02 \div 0.01028 = 1.95 \)
The two-sided p-value is just above 0.05 (about 0.052), so at \( \alpha = 0.05 \) we fail to reject \( H_0 \). Advice: collect more data before rolling out or abandoning the new page.
ExamQ6. A clinic compares recovery times for two therapies. Therapy 1: \( n = 25,\ \bar{x} = 14 \) days, \( s = 5 \). Therapy 2: \( n = 25,\ \bar{x} = 17 \) days, \( s = 6 \). (a) Identify the design. (b) Compute the SE of the difference. (c) With df = 24 and \( t^{*} = 2.064 \), build a 95% interval for \( \mu_1 – \mu_2 \). (d) Do the therapies differ significantly? Justify. [6 marks] Show worked answer
(a) Independent samples: two separate groups of patients [1].
(b) \( SE = \sqrt{25/25 + 36/25} = \sqrt{1 + 1.44} = \sqrt{2.44} = 1.562 \) [1 for method, 1 for answer].
(c) Difference \( = 14 – 17 = -3 \). Margin \( = 2.064 \times 1.562 = 3.22 \). Interval \( = -3 \pm 3.22 = (-6.22,\ 0.22) \) days [2].
(d) The interval contains zero, so the therapies do not differ significantly at the 5% level [1]. It only just includes zero, so a larger study would be worthwhile; this is not proof that the therapies are equally effective.

Check yourself

1. Twenty people have their reaction time measured before and after drinking coffee. Which procedure fits?

The same people are measured twice, so the data is paired and you analyse the differences.

2. Why does the two-proportion test use a pooled proportion?

Pooling follows from the null hypothesis; the interval makes no such assumption, so it does not pool.

3. A 95% interval for \( \mu_1 – \mu_2 \) is \( (-2,\ 7) \). What do you conclude at \( \alpha = 0.05 \)?

An interval that contains zero means zero is a plausible difference, so you fail to reject \( H_0 \).

Your score: 0 out of 3

The short version

  • Comparing two groups means estimating a difference. The key question is whether zero is a plausible value for it.
  • Identify the design first: independent (separate people) or paired (same or matched people). The wrong procedure loses power or is invalid.
  • Independent means: \( SE = \sqrt{s_1^2/n_1 + s_2^2/n_2} \), df = smaller \( n – 1 \). Paired data: work out the differences and use one-sample methods with df = pairs − 1.
  • Two proportions: pooled SE for the test, each group’s own \( \hat{p} \) for the interval; you need at least 10 successes and 10 failures per group.
  • Always report the interval, not just the p-value, and never stop an A/B test early. The full chapter in Statistics Made Simple has 58 practice questions with a complete answer key.
Want more questions like these, with worked answers?
The practice book has hundreds more, graded from easy to exam level.
Next: step 19 of 22Exploring Relationships