Tutorials › Introduction to Statistics › Worked Confidence Intervals for Two Proportions

Two-Proportion Inference · Tutorial 703 of 996

Worked Confidence Intervals for Two Proportions

Learn to calculate and report confidence intervals for the difference between two independent-group risks using success counts and sample proportions.

Intermediate 9 min read

What You'll Learn

  • Define the direction of a risk difference before calculating it.
  • Convert success counts into sample proportions for two independent groups.
  • Calculate the unpooled standard error for a difference in proportions.
  • Use a critical value to find confidence interval endpoints.
  • Report the estimated risk difference and interval in context and percentage points.
  • Recognize why the interval's standard error is not pooled.

From Two Sets of Counts to a Risk Difference

When an outcome is recorded as either a success or a failure, its risk in a group is the proportion of individuals in that group who experience the outcome. To compare two groups, we estimate each risk from its observed success count and calculate their difference. A confidence interval describes the uncertainty in that estimated difference.

The order of subtraction matters. In this tutorial, group 1 is the group named first and group 2 is the comparison group. The risk difference is defined as group 1's risk minus group 2's risk. A positive estimate means the observed risk is higher in group 1; a negative estimate means it is lower. The difference is measured in proportion units, or equivalently in percentage points after multiplying by 100.

Definition: Let \(x_1\) and \(x_2\) be the numbers of successes among \(n_1\) and \(n_2\) individuals in two independent groups. The sample proportions are \(\hat{p}_1=x_1/n_1\) and \(\hat{p}_2=x_2/n_2\). The estimated risk difference, in the stated group order, is \(\hat{p}_1-\hat{p}_2\), estimating the population risk difference \(p_1-p_2\).

For a confidence interval using the usual large-sample normal approximation, each individual has a binary outcome, observations within each group are independent, and the two groups are independent. The sample sizes are treated as fixed. The groups should also represent the populations about which conclusions are intended; if the data are not from a randomized experiment, a difference in risks alone does not establish a causal effect. The approximation is most dependable when both groups have enough successes and failures.

The Interval and Its Standard Error

The confidence interval for \(p_1-p_2\) uses the sample difference as its center. Its standard error is estimated separately in each group and then combined. This is an unpooled standard error: each group contributes its own estimated risk and sample size.

Formula: For a confidence level with standard-normal critical value \(z^*\), the large-sample confidence interval for \(p_1-p_2\) is
$$ (\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}}. $$
The square-root term is the estimated standard error, \(SE\). For a 95% confidence interval, \(z^*\) is approximately 1.96; for a 90% interval, it is approximately 1.645.

The estimated standard error measures the typical sampling variability of the estimated difference under the model. The plus-or-minus part is the margin of error. Subtracting and adding that margin to the estimate gives the lower and upper endpoints. Keep adequate precision in intermediate calculations and round the endpoints only at the end; otherwise, rounded components can produce endpoints that do not agree arithmetically.

Why the Standard Error Has This Form

The formula follows from the independent Bernoulli model. In group \(i\), let \(X_i\) count successes in \(n_i\) independent trials, each with success probability \(p_i\). Then the sample proportion is \(X_i/n_i\). For a Bernoulli outcome, the variance is \(p_i(1-p_i)\), so the variance of the sum of \(n_i\) independent outcomes is \(n_i p_i(1-p_i)\). Dividing by \(n_i^2\) gives the variance of the sample proportion:

$$ \operatorname{Var}(\hat{p}_i) =\operatorname{Var}\left(\frac{X_i}{n_i}\right) =\frac{n_i p_i(1-p_i)}{n_i^2} =\frac{p_i(1-p_i)}{n_i}. $$

Because the groups are independent, the covariance between their sample proportions is zero. The variance of a difference is therefore the sum of the two variances, whether the difference is written as \(\hat{p}_1-\hat{p}_2\) or in the reverse order. Replacing the unknown \(p_i\) values by their sample estimates gives the estimated variance and standard error in the interval formula. When the sample proportions are approximately normally distributed, a critical-value multiple of that standard error provides the stated confidence interval.

Worked Calculations

Worked Example: Comparing Two Hypothetical Risks

In a hypothetical comparison of two independent groups, 42 of 120 individuals in group 1 experience an outcome, compared with 25 of 110 individuals in group 2. Calculate a 95% confidence interval for the risk difference \(p_1-p_2\).

Check the setup. Assume the group samples are independent and individuals within each group have independent binary outcomes. The observed success and failure counts are 42 and 78 in group 1, and 25 and 85 in group 2. Each count is comfortably above 10, so the normal approximation is reasonable for this illustration.

Sample proportions and estimated difference.

$$ \hat{p}_1=\frac{42}{120}=0.3500,\qquad \hat{p}_2=\frac{25}{110}=0.2273, \qquad \hat{p}_1-\hat{p}_2=0.1227. $$

Standard error. Use each group's own sample proportion:

$$ SE= \sqrt{\frac{(0.3500)(0.6500)}{120} +\frac{(25/110)(85/110)}{110}} \approx 0.05910. $$

For 95% confidence, the margin of error is \(1.96(0.0590963)\), approximately 0.11583. Using the unrounded proportions and standard error to calculate the endpoints:

$$ \left(\frac{42}{120}-\frac{25}{110}\right) \pm 1.96 \sqrt{\frac{(42/120)(1-42/120)}{120} +\frac{(25/110)(1-25/110)}{110}} \approx (0.0069,\ 0.2386). $$

The estimated risk in group 1 is 0.1227, or about 12.27 percentage points, higher than in group 2. The 95% confidence interval for the population risk difference is about 0.0069 to 0.2386, equivalently 0.69 to 23.86 percentage points, with group 1 minus group 2 as the direction.

Worked Example: A Larger Positive Difference

Suppose a hypothetical study observes the outcome in 38 of 90 individuals in group 1 and 21 of 85 individuals in group 2. Find a 95% confidence interval for \(p_1-p_2\).

Assume independent group samples and independent binary outcomes within each group. The success and failure counts are 38 and 52, and 21 and 64, respectively. Since all four counts exceed 10, the large-sample normal approximation is plausible.

The estimated risks and their difference are

$$ \hat{p}_1=\frac{38}{90}=0.4222,\qquad \hat{p}_2=\frac{21}{85}=0.2471,\qquad \hat{p}_1-\hat{p}_2=0.1752. $$

The estimated standard error combines the two group-specific contributions:

$$ SE= \sqrt{\frac{(38/90)(52/90)}{90} +\frac{(21/85)(64/85)}{85}} \approx 0.06999. $$

The 95% margin of error is \(1.96(0.0699932)\), approximately 0.13719. Thus, calculating with unrounded inputs,

$$ \left(\frac{38}{90}-\frac{21}{85}\right) \pm 1.96 \sqrt{\frac{(38/90)(52/90)}{90} +\frac{(21/85)(64/85)}{85}} \approx (0.0380,\ 0.3124). $$

The observed risk is about 17.52 percentage points higher in group 1. The interval runs from about 3.80 to 31.24 percentage points for the population difference, again group 1 minus group 2.

Worked Example: An Estimated Difference Below Zero

In another hypothetical comparison, 16 of 80 individuals in group 1 and 24 of 100 in group 2 experience the outcome. Calculate a 90% confidence interval for \(p_1-p_2\).

Assume the two groups and the outcomes within each group are independent. The success and failure counts are 16 and 64 in group 1, and 24 and 76 in group 2. All counts exceed 10, supporting a normal approximation here.

The sample proportions are 0.2000 and 0.2400, so the estimated difference is \(-0.0400\). The standard error is

$$ SE= \sqrt{\frac{(0.2000)(0.8000)}{80} +\frac{(0.2400)(0.7600)}{100}} = \sqrt{0.002000+0.001824} \approx 0.06184. $$

For a 90% interval, use \(z^*=1.645\). The margin of error is \(1.645(0.0618385)\approx0.10172\), so the endpoints are

$$ -0.0400\pm 1.645(0.0618385) \approx (-0.1417,\ 0.0617). $$

In this sample, the observed risk is 4.00 percentage points lower in group 1. The calculated 90% interval extends from about 14.17 percentage points lower to 6.17 percentage points higher for the population risk in group 1 relative to group 2.

A Reliable Calculation Routine

A consistent order helps prevent sign errors and misplaced denominators. In particular, define the group order before subtracting and keep each group's proportion paired with its own sample size in the standard error.

1
Specify the direction.
Write the target as \(p_1-p_2\) and identify which group is group 1.
2
Calculate the proportions.
For each group, divide its success count by its own sample size: \(\hat{p}_i=x_i/n_i\).
3
Calculate the estimate and standard error.
Subtract the sample proportions in the chosen order. Add the two group-specific estimated variances and take the square root.
4
Apply the critical value and report.
Calculate estimate \(\pm z^*SE\), retain precision until the endpoints are found, and state the group order and units in context.

Common Mistakes and Why the Interval Matters

  • Reversing the groups without changing the interpretation. The interval for \(p_1-p_2\) is not the interval for \(p_2-p_1\). Reversing the order changes the sign of the estimate and swaps and negates the endpoints.
  • Using a pooled standard error for this interval. The confidence interval estimates each group's risk separately, so its standard error uses \(\hat{p}_1(1-\hat{p}_1)/n_1\) and \(\hat{p}_2(1-\hat{p}_2)/n_2\). A pooled proportion does not belong in this interval formula.
  • Pairing a proportion with the wrong sample size. The first variance contribution must use group 1's proportion and \(n_1\); the second must use group 2's proportion and \(n_2\).
  • Rounding too early. A rounded estimate and rounded margin may not reproduce endpoints computed from full precision. Use unrounded inputs for the final endpoint calculation, then round the endpoints consistently.
  • Calling a risk difference a relative change. A difference such as 0.12 means a difference of 12 percentage points, not necessarily a 12% increase. Relative comparisons use a different measure.

A confidence interval is useful because it presents both a point estimate and the uncertainty associated with that estimate, in the same units as the difference. Its calculation depends on the two independent-group proportions and their sample sizes, not on a shared or pooled estimate of risk. A carefully stated group order, sound assumptions, and consistent arithmetic make the result interpretable.

Key takeaway: For an independent-group risk difference, calculate \(\hat{p}_1-\hat{p}_2\), use the unpooled standard error based on both group proportions, and report the confidence interval with its direction and context.

Check Your Understanding

Answer each question using the two-proportion confidence interval method.

  1. In a comparison, which population difference is estimated if group 1 is defined as the treatment group and the calculation is \(\hat{p}_1-\hat{p}_2\)?
  2. Why does the confidence interval standard error add two variance contributions rather than use one pooled proportion?
  3. A group has 30 successes among 100 individuals. What is its sample proportion, and how many failures were observed?
  4. For a 95% interval, the estimated difference is 0.08 and the standard error is 0.03. Using \(z^*=1.96\), calculate the margin of error and endpoints.
  5. What should happen to the signs of the estimate and interval endpoints if the group order is reversed?