Statistics & Probability · Grade 12 and undergraduate

Comparing Two Groups: Two-Sample z and t Procedures

Quick answer

Many questions compare two groups: a new drug against the old one, or one class against another. For two proportions, the difference p̂₁ − p̂₂ has standard error √(p̂₁(1 − p̂₁)/n₁ + p̂₂(1 − p̂₂)/n₂), and a test of no difference uses the pooled proportion. For two means, the difference x̄₁ − x̄₂ has standard error √(s₁²/n₁ + s₂²/n₂) and follows a t distribution. In both cases the variances add, because the two samples vary independently.

What you'll learn

  • Build a confidence interval for a difference of two proportions
  • Test whether two proportions differ, using the pooled proportion
  • Build an interval and run a test for a difference of two means
  • Explain why the variances of the two estimates add

The difference between two estimates

To compare two groups, estimate each one and look at the difference. Because the two samples are independent, the variance of the difference is the sum of the two variances, as in combining random variables:

ComparingEstimateStandard error
two proportionsp^1−p^2\hat{p}_1 - \hat{p}_2p^1(1−p^1)n1+p^2(1−p^2)n2\sqrt{\tfrac{\hat{p}_1(1 - \hat{p}_1)}{n_1} + \tfrac{\hat{p}_2(1 - \hat{p}_2)}{n_2}}
two meansxˉ1−xˉ2\bar{x}_1 - \bar{x}_2s12n1+s22n2\sqrt{\tfrac{s_1^2}{n_1} + \tfrac{s_2^2}{n_2}}

Intervals are estimate ±\pm critical value ×\times standard error, with z∗z^* for proportions and t∗t^* for means.

Testing two proportions. Under H0:p1=p2H_0: p_1 = p_2, both samples estimate one common pp. Combine them into the pooled proportion p^=x1+x2n1+n2\hat{p} = \tfrac{x_1 + x_2}{n_1 + n_2} and use

z=p^1−p^2p^(1−p^)(1n1+1n2)z = \frac{\hat{p}_1 - \hat{p}_2}{\sqrt{\hat{p}(1 - \hat{p})\left(\tfrac{1}{n_1} + \tfrac{1}{n_2}\right)}}

Testing two means. Use t=xˉ1−xˉ2s12/n1+s22/n2t = \tfrac{\bar{x}_1 - \bar{x}_2}{\sqrt{s_1^2/n_1 + s_2^2/n_2}}. By hand, take the degrees of freedom as the smaller of n1−1n_1 - 1 and n2−1n_2 - 1; software uses a slightly larger value from Welch’s formula.

Why variances add, even for a difference

Each estimate wobbles from sample to sample. When one estimate comes out high and the other low, the difference is pushed further from the truth, not closer. Independent errors never cancel on average, so subtracting two estimates adds their variances. The standard deviations do not add; the variances do, and the square root comes last.

Worked examples

Common mistakes

Practice problems

  1. In one group 4545 of 100100 agree; in another, 3030 of 100100. Find the pooled proportion.

    Answer

    0.3750.375

    Full solution

    45+30200=75200\tfrac{45 + 30}{200} = \tfrac{75}{200}.

  2. For Exercise 1, test H0:p1=p2H_0: p_1 = p_2 against Ha:p1≠p2H_a: p_1 \ne p_2.

    Answer

    z≈2.19z \approx 2.19, p-value ≈0.028\approx 0.028; reject at α=0.05\alpha = 0.05.

    Full solution

    The standard error is 0.375(0.625)(0.02)≈0.0685\sqrt{0.375(0.625)(0.02)} \approx 0.0685, and z=0.150.0685z = \tfrac{0.15}{0.0685}.

  3. For Exercise 1, find a 95%95\% confidence interval for p1−p2p_1 - p_2.

    Answer

    About (0.017, 0.283)(0.017,\ 0.283)

    Full solution

    The standard error is 0.45(0.55)100+0.3(0.7)100≈0.0676\sqrt{\tfrac{0.45(0.55)}{100} + \tfrac{0.3(0.7)}{100}} \approx 0.0676, and 0.15±1.96×0.06760.15 \pm 1.96 \times 0.0676.

  4. Two groups of 1515 have means 3131 and 2727, with s=4s = 4 and s=5s = 5. Find the two-sample t statistic.

    Answer

    t≈2.42t \approx 2.42

    Full solution

    The standard error is 1615+2515≈1.65\sqrt{\tfrac{16}{15} + \tfrac{25}{15}} \approx 1.65, and t=41.65t = \tfrac{4}{1.65}.

  5. For Exercise 4, using 1414 df, is the difference significant at α=0.05\alpha = 0.05 (two-sided)?

    Answer

    Yes

    Full solution

    The p-value is about 0.0300.030.

    With 1414 df, t∗=2.145t^* = 2.145 for 95%95\%, and 2.42>2.1452.42 > 2.145.

  6. Two independent estimates have standard errors 33 and 44. What is the standard error of their difference?

    Answer

    55

    Full solution

    9+16=5\sqrt{9 + 16} = 5, not 3+43 + 4 and not 4−34 - 3.

  7. In Example 3, find a 95%95\% confidence interval for μA−μB\mu_A - \mu_B with 1919 df (t∗=2.093t^* = 2.093).

    Answer

    About (0.38, 11.62)(0.38,\ 11.62)

    Full solution

    6±2.093×2.683=6±5.626 \pm 2.093 \times 2.683 = 6 \pm 5.62.

  8. A student computes the standard error in Example 3 as 820+1025≈3.79\tfrac{8}{\sqrt{20}} + \tfrac{10}{\sqrt{25}} \approx 3.79. What went wrong?

    Answer

    Standard errors were added instead of variances.

    Full solution

    The correct value is 3.2+4≈2.68\sqrt{3.2 + 4} \approx 2.68. Adding the standard errors overstates the uncertainty.

Frequently asked questions

How do you test whether two proportions differ?

Use z = (p̂₁ − p̂₂)/√(p̂(1 − p̂)(1/n₁ + 1/n₂)), where p̂ is the pooled proportion of successes in both samples combined.

What is the standard error of a difference of two means?

√(s₁²/n₁ + s₂²/n₂). The squared standard errors of the two means add.

How many degrees of freedom does a two-sample t-test have?

Software uses a formula (Welch's) that gives a value between the smaller of n₁ − 1 and n₂ − 1 and n₁ + n₂ − 2. By hand, using the smaller of n₁ − 1 and n₂ − 1 is a safe, slightly cautious choice.

Why pool for the test but not the interval?

The test assumes the null hypothesis p₁ = p₂, so both samples estimate the same p. The interval makes no such assumption.

When should I use a paired test instead?

When the two measurements come in natural pairs, such as the same person before and after. Two-sample procedures are for independent groups.

What to learn next

Standards alignment

This lesson covers the following Common Core State Standards for Mathematics.

  • CCSS.MATH.CONTENT.HSS.IC.B.5Making Inferences and Justifying ConclusionsUse data from a randomized experiment to compare two treatments; use simulations to decide if differences between parameters are significant.