UK-based online statistics and data analysis support for USA, UK, and international clients. No exams, no impersonation, no fabricated data.
Z Tests

Two Proportion Z Test: Formula, Example, Calculator, SPSS, R, Python and Excel Guide

Hypothesis Test for Comparing Two Proportions Two Proportion Z Test is used to test whether two independent population proportions are significantly different. This guide explains the...

Statistics guide Ethical learning support SPSS/R/Python/Excel friendly
Two Proportion Z Test: Formula, Example, Calculator, SPSS, R, Python and Excel Guide

Hypothesis Test for Comparing Two Proportions

Two Proportion Z Test is used to test whether two independent population proportions are significantly different. This guide explains the two sample z test for proportions with formula, assumptions, conditions, p-value, confidence interval, SPSS image output, Python charts, R validation charts and Excel workflow using school pass-rate data where pass = G3 ≥ 10.

Advertisement
Google AdSense top placement reserved here

Quick Answer: Two Proportion Z Test Result

The Two Proportion Z Test was performed to compare the final exam pass proportion between two schools: GP and MS. A student was coded as pass if G3 ≥ 10 and fail if G3 < 10.

In the GP school, 391 students passed out of 423, giving p1 = 0.9243. In the MS school, 158 students passed out of 226, giving p2 = 0.6991. The observed difference was p1 − p2 = 0.2252, meaning the GP pass proportion was about 22.5 percentage points higher than the MS pass proportion.

GP pass rate391/423 = 0.924
MS pass rate158/226 = 0.699
Difference0.225
DecisionReject H₀

The pooled proportion used for the hypothesis test was 0.8459. The pooled standard error was 0.0297. The z statistic was z = 7.5717, and the two-tailed p-value was approximately 3.68 × 10-14. In a final report, this should be written as p < .001. The 95% confidence interval for the difference in pass proportions was [0.1603, 0.2901].

Final conclusion: Since p < .001, reject the null hypothesis. The sample provides strong evidence that the pass proportions are significantly different between GP and MS. Because the observed difference is positive, the GP school has a significantly higher pass proportion than the MS school.

Important reporting note: Some software may display very small p-values as .000. Do not write p = .000. The correct reporting style is p < .001.

Table of Contents

  1. What Is a Two Proportion Z Test?
  2. When to Use Two Proportion Z Test
  3. Null and Alternative Hypothesis
  4. Two Proportion Z Test Formula
  5. Conditions and Assumptions
  6. Dataset and Variable Coding
  7. Verified Results Summary
  8. SPSS Image Output and Interpretation
  9. Python Charts and Interpretation
  10. R Validation Charts and Interpretation
  11. Overall Image Interpretation
  12. How to Run the Test in SPSS, Python, R and Excel
  13. How to Report the Two Proportion Z Test
  14. Common Mistakes
  15. FAQs

What Is a Two Proportion Z Test?

A Two Proportion Z Test is a statistical hypothesis test used to compare two independent sample proportions. It is also called a two sample z test for proportions, two sample z proportion test or z test for two proportions.

The test is used when the outcome variable has two categories, such as pass/fail, yes/no, success/failure or converted/not converted. The grouping variable must have two independent groups. In this example, the outcome is final exam status and the grouping variable is school. The two school groups are GP and MS.

The main question is: Is the pass proportion at GP significantly different from the pass proportion at MS? The test compares p1 and p2. If the difference between the two sample proportions is large relative to its standard error, the z statistic becomes large and the p-value becomes small.

For background concepts, see Null and Alternative Hypothesis, P Value, Z Score, Standard Error, Standard Normal Distribution and Cross Tabulation.

When Should You Use a Two Proportion Z Test?

Use a two proportion z test when you want to compare two independent proportions. It is appropriate when the outcome is binary and each case belongs to only one of the two groups.

SituationUse Two Proportion Z Test?Reason
Comparing pass rate between GP and MS schoolsYesThe outcome is pass/fail and there are two independent school groups.
Comparing conversion rate between two landing pagesYesThe outcome is converted/not converted and the groups are independent.
Comparing support rate between two survey groupsYesThe outcome is support/no support across two groups.
Testing whether one pass proportion differs from 50%NoThat is a one-sample proportion question. Use a One Proportion Z Test.
Comparing average G3 score between two schoolsNoThat is a mean comparison, not a proportion comparison.

The one proportion vs two proportion z test difference is simple: one proportion z test compares one observed proportion with one benchmark value, while two proportion z test compares two observed proportions from two groups.

Null and Alternative Hypothesis for Two Proportion Z Test

The hypotheses compare the two population proportions. In this example, p1 is the GP pass proportion and p2 is the MS pass proportion.

HypothesisSymbolic formMeaning in this example
Null hypothesisH0: p1 = p2The GP and MS population pass proportions are equal.
Alternative hypothesisH1: p1 ≠ p2The GP and MS population pass proportions are different.
Equivalent difference formH0: p1 − p2 = 0There is no population pass-rate difference between schools.
Decision ruleReject H0 if p-value < αUsing α = .05, reject H0 because p < .001.

This example uses a two-tailed two proportion z test because the alternative hypothesis says the proportions are different. A right-tailed test would use H1: p1 > p2, and a left-tailed test would use H1: p1 < p2.

Two Proportion Z Test Formula and Exact Calculation

The two proportion z test formula compares two sample proportions using a pooled standard error under the null hypothesis.

z = (p1 - p2) / SEpooled

p1 = x1 / n1
p2 = x2 / n2

pooled p = (x1 + x2) / (n1 + n2)

SEpooled = sqrt[pooled p × (1 - pooled p) × (1/n1 + 1/n2)]

For this worked example:

ComponentExact valueExplanation
Group 1GPFirst school group.
Group 2MSSecond school group.
GP successesx1 = 391GP students who passed.
GP sample sizen1 = 423Total GP students.
MS successesx2 = 158MS students who passed.
MS sample sizen2 = 226Total MS students.
GP pass proportionp1 = 391/423 = 0.9243About 92.4% of GP students passed.
MS pass proportionp2 = 158/226 = 0.6991About 69.9% of MS students passed.
Differencep1 − p2 = 0.2252GP is 22.5 percentage points higher than MS.
Pooled proportion0.8459Combined pass proportion under H0.
Pooled standard error0.0297Standard error used for the z statistic.
Z statistic7.5717Observed difference is 7.57 pooled standard errors above zero.
Two-tailed p-valuep < .001Reject the null hypothesis.
p1 = 391 / 423 = 0.9243
p2 = 158 / 226 = 0.6991

difference = p1 - p2
difference = 0.9243 - 0.6991
difference = 0.2252

pooled p = (391 + 158) / (423 + 226)
pooled p = 549 / 649
pooled p = 0.8459

SEpooled = sqrt[0.8459 × (1 - 0.8459) × (1/423 + 1/226)]
SEpooled = 0.0297

z = 0.2252 / 0.0297
z = 7.5717

Why Do We Pool for the Two-Proportion Z-Test?

The test pools the two sample proportions because the null hypothesis says the two population proportions are equal. If H0: p1 = p2 is true, both groups estimate one common population proportion. That common estimate is the pooled proportion.

The confidence interval for the difference is usually calculated with the unpooled standard error because the interval estimates the actual size of the difference, not the null condition of equality. In this example, the 95% confidence interval for p1 − p2 is [0.1603, 0.2901].

Conditions and Assumptions for Two Proportion Z Test

The conditions for two proportion z test explain when the z approximation is appropriate. These conditions should be checked before interpreting the p-value.

ConditionHow to check itThis example
Binary outcomeThe outcome must have two categories.Pass = G3 ≥ 10; Fail = G3 < 10.
Two independent groupsEach case belongs to only one group.Each student belongs to either GP or MS.
Independent observationsEach row should represent a separate case.Each row is treated as one student record.
Large-sample conditionEach group should have enough expected successes and failures.All school pass/fail counts are large enough for the z approximation.
No repeated measurement of the same caseThe two groups should not be paired or matched.GP and MS are independent school groups.

If the sample counts are very small, an exact method may be safer. With 423 GP students and 226 MS students, the sample size condition is satisfied.

Dataset and Variable Coding

This worked example uses student performance data. The final grade variable is G3. A binary pass/fail outcome was created from G3. A student was coded as pass if G3 ≥ 10 and fail if G3 < 10.

ItemValueExplanation
Outcome variablepass_finalBinary pass/fail variable created from G3.
Success definitionG3 ≥ 10Student passed the final exam.
Failure definitionG3 < 10Student did not pass the final exam.
Grouping variableschoolTwo independent school groups: GP and MS.
GP group391 pass, 32 fail, n = 423GP pass proportion = 0.9243.
MS group158 pass, 68 fail, n = 226MS pass proportion = 0.6991.

External dataset source: UCI Machine Learning Repository: Student Performance dataset.

Advertisement
Google AdSense middle placement reserved here

Verified SPSS, Python and R Results Summary

The SPSS image output, Python charts and R validation charts all support the same decision. GP has a higher pass proportion than MS. The difference is 0.2252, the confidence interval is entirely above zero, and the z statistic is far beyond the usual ±1.96 critical values.

StatisticExact valueInterpretation
GP pass count391Students who passed in GP.
GP total423Total GP students.
GP pass proportion0.924392.4% passed.
MS pass count158Students who passed in MS.
MS total226Total MS students.
MS pass proportion0.699169.9% passed.
Difference0.2252GP is 22.5 percentage points higher.
95% CI for difference[0.1603, 0.2901]The interval is entirely above zero.
Z statistic7.5717The result is far into the rejection region.
p-valuep < .001Reject H0.

SPSS Image Output and Interpretation

The SPSS image output explains the Two Proportion Z Test visually. These images show the raw school pass/fail counts, the two pass proportions, the confidence interval for the difference, the z statistic on the standard normal curve and subgroup context by sex and study time.

1. SPSS Image: Pass and Fail Counts by School

SPSS Two Proportion Z Test pass fail counts by school
SPSS image showing pass and fail counts for GP and MS schools.

This SPSS image shows the raw counts used in the Two Proportion Z Test. In the GP school, 391 students passed and 32 failed. In the MS school, 158 students passed and 68 failed.

The chart is important because it shows the data before any statistical formula is applied. The GP school has a much larger pass count and a much smaller fail count relative to its total. The MS school still has more passes than failures, but the failure count is much larger relative to its group size.

These counts directly produce the sample proportions: 391/423 = 0.9243 for GP and 158/226 = 0.6991 for MS. Therefore, this image is the foundation of the entire z-test calculation.

2. SPSS Image: Pass Proportion Comparison by School

SPSS Two Proportion Z Test pass proportion comparison by school
SPSS image comparing GP and MS pass proportions.

This SPSS image compares the two observed pass proportions. The GP pass proportion is 0.924, while the MS pass proportion is 0.699. The difference is 0.225, meaning GP is about 22.5 percentage points higher than MS.

This image shows the central comparison in the Two Proportion Z Test. The null hypothesis says the two population pass proportions are equal. The observed data show a clear difference between the two schools.

The chart also gives practical meaning to the result. Even before looking at the p-value, the difference is large enough to matter educationally: roughly 92% of GP students passed, compared with roughly 70% of MS students.

3. SPSS Image: Confidence Interval for Difference in Proportions

SPSS confidence interval for difference in two proportions
SPSS image showing the 95% confidence interval for pGP − pMS.

This SPSS image shows the confidence interval for the difference between the two pass proportions. The observed difference is 0.225, and the 95% confidence interval is [0.160, 0.290].

The dashed no-difference line is located at 0. The entire confidence interval is above zero. This means the estimated GP pass proportion is higher than the MS pass proportion even after accounting for sampling uncertainty.

The confidence interval also gives practical size. It suggests that the GP pass proportion is likely between about 16.0 and 29.0 percentage points higher than the MS pass proportion.

4. SPSS Image: Z Statistic on the Standard Normal Curve

SPSS Two Proportion Z Test z statistic on standard normal curve
SPSS image showing the observed z statistic on the standard normal curve.

This SPSS image places the test statistic on the standard normal curve. The observed value is z = 7.57. For a two-tailed test at α = .05, the usual critical values are ±1.96.

The observed z statistic is far to the right of +1.96. This means the observed difference in pass proportions is far larger than what would normally be expected if the two population proportions were equal.

The curve image explains why the p-value is extremely small. A z value of 7.57 is deep in the rejection region. Therefore, the test rejects the null hypothesis of equal pass proportions.

5. SPSS Image: Pass/Fail Percentage Composition by School

SPSS pass fail percentage composition by school for Two Proportion Z Test
SPSS image showing pass/fail percentage composition for GP and MS.

This SPSS stacked percentage image shows the composition of each school group. GP has a pass percentage of 92.4% and a fail percentage of 7.6%. MS has a pass percentage of 69.9% and a fail percentage of 30.1%.

This chart is useful because it puts both groups on the same 0 to 100% scale. It makes the school difference easier to compare visually than raw counts alone.

The stacked bars show that failure occupies a much larger share of the MS bar than the GP bar. This supports the main conclusion that school is associated with a meaningful difference in pass proportion.

6. SPSS Image: Pass Proportion by Sex Within School

SPSS pass proportion by sex within school for Two Proportion Z Test context
SPSS image showing pass proportions by sex within each school.

This SPSS image provides subgroup context by sex within school. Among female students, GP has 228 passes out of 237, or 96.2%, while MS has 105 passes out of 146, or 71.9%. Among male students, GP has 163 passes out of 186, or 87.6%, while MS has 53 passes out of 80, or 66.3%.

The chart shows that the GP pass proportion is higher than the MS pass proportion for both female and male students. This supports the overall school comparison because the school difference is not limited to only one sex category.

This image is descriptive context. The formal Two Proportion Z Test compares overall GP and MS pass proportions. If the research question were about sex-by-school interaction, a more detailed model would be needed.

7. SPSS Image: Pass Proportion by Study Time Within School

SPSS pass proportion by study time within school for Two Proportion Z Test context
SPSS image showing pass proportions by study time within each school.

This SPSS image shows pass proportions by study-time category within each school. In study-time category 1, GP has 100/119 = 84.0% passing, while MS has 62/93 = 66.7%. In category 2, GP has 196/206 = 95.1%, while MS has 68/99 = 68.7%. In category 3, GP has 68/71 = 95.8%, while MS has 22/26 = 84.6%. In category 4, GP has 27/27 = 100.0%, while MS has 6/8 = 75.0%.

The pattern shows that GP has a higher pass proportion than MS in every study-time category. This strengthens the descriptive interpretation because the overall school difference appears across different levels of study time.

However, this chart is still descriptive. The formal test in this post compares the two overall school proportions. A separate regression or stratified analysis would be required to formally adjust for study time.

Python Charts and Interpretation

The Python charts validate the same Two Proportion Z Test result with a programmatic workflow. They confirm the raw counts, the pass proportion comparison, the confidence interval, the z statistic and the subgroup patterns.

1. Python Chart: Pass and Fail Counts by School

Python Two Proportion Z Test pass fail counts by school
Python chart showing pass and fail counts by school.

The Python count chart confirms the same values used in the SPSS output. GP has 391 passes and 32 failures. MS has 158 passes and 68 failures.

This chart is the first validation point because the z test depends on the correct count of successes and total cases in each group. The Python output matches the SPSS image, so the data coding is consistent.

The visual difference between the two schools is clear. GP has a much smaller failure share than MS, which leads to the higher GP pass proportion.

2. Python Chart: Pass Proportion Comparison by School

Python Two Proportion Z Test pass proportion comparison by school
Python chart comparing GP and MS pass proportions.

The Python proportion chart shows pGP = 0.924 and pMS = 0.699. The chart also states the difference as approximately 0.225.

This is the central visual comparison for the two sample z test for proportions. The difference between the bars is large enough to be practically meaningful and statistically meaningful.

Because Python confirms the same pass proportions as SPSS, it validates the result from an independent workflow.

3. Python Chart: Confidence Interval for Difference in Proportions

Python confidence interval for difference in proportions
Python chart showing the 95% confidence interval for the difference in pass proportions.

The Python confidence interval chart confirms that the estimated difference is 0.225 with a 95% confidence interval of about [0.160, 0.290].

The full interval is above zero, so the data support a positive difference between GP and MS. This means GP has a higher pass proportion than MS.

The confidence interval gives practical interpretation: the true difference is likely between 16.0 and 29.0 percentage points.

4. Python Chart: Z Statistic on the Standard Normal Curve

Python Two Proportion Z Test z statistic standard normal curve
Python chart showing z = 7.57 on the standard normal curve.

The Python standard normal curve chart shows the observed z statistic relative to the normal distribution. The observed value is z = 7.57.

This value is far beyond the ordinary two-tailed critical values of ±1.96. Therefore, the observed difference in school pass proportions is far outside the expected range under the null hypothesis of equal proportions.

The Python chart confirms the p-value decision: the result is statistically significant, and the null hypothesis should be rejected.

5. Python Chart: Pass/Fail Percentage Composition by School

Python pass fail percentage composition by school
Python chart showing pass/fail percentage composition by school.

The Python percentage composition chart places both schools on the same proportional scale. GP has 92.4% pass and 7.6% fail. MS has 69.9% pass and 30.1% fail.

This chart is useful for readers because it avoids confusion caused by unequal sample sizes. GP has 423 students and MS has 226 students, so percentages are easier to compare than raw counts alone.

The image confirms that MS has a much larger failure share, which explains the lower MS pass proportion.

6. Python Chart: Pass Proportion by Sex Within School

Python pass proportion by sex within school for Two Proportion Z Test
Python chart showing pass proportions by sex within each school.

The Python sex-within-school chart shows the same subgroup pattern as SPSS. GP has higher pass proportions than MS for both female and male students. Female students: GP = 96.2%, MS = 71.9%. Male students: GP = 87.6%, MS = 66.3%.

This chart helps explain the overall school difference. The GP advantage appears within both sex categories, not only in one subgroup.

The chart is descriptive and does not replace the main two proportion z test. It helps readers understand the data pattern behind the overall school comparison.

7. Python Chart: Pass Proportion by Study Time Within School

Python pass proportion by study time within school for Two Proportion Z Test
Python chart showing pass proportions by study time within each school.

The Python study-time chart shows pass proportions for GP and MS across study-time categories 1 through 4. GP remains higher than MS in every category.

The exact values are: study time 1, GP = 84.0% and MS = 66.7%; study time 2, GP = 95.1% and MS = 68.7%; study time 3, GP = 95.8% and MS = 84.6%; study time 4, GP = 100.0% and MS = 75.0%.

This chart supports the descriptive conclusion that GP has a stronger pass proportion across study-time groups. The formal inferential conclusion still comes from the overall Two Proportion Z Test.

R Validation Charts and Interpretation

The R charts provide another independent validation of the same result. R confirms the count structure, school pass proportions, confidence interval, z statistic and subgroup patterns.

1. R Chart: Pass and Fail Counts by School

R Two Proportion Z Test pass fail counts by school
R validation chart showing pass and fail counts by school.

The R count chart confirms that the same data are being used across software. GP has 391 passes and 32 failures, while MS has 158 passes and 68 failures.

This verifies that the R workflow uses the same pass/fail coding as SPSS and Python. Since the counts match, the computed proportions and z statistic should also match.

The count pattern again shows the core reason for the significant result: GP has a much smaller failure share than MS.

2. R Chart: Pass Proportion Comparison by School

R Two Proportion Z Test pass proportion comparison by school
R validation chart comparing GP and MS pass proportions.

The R proportion chart confirms p1 = 0.924 for GP and p2 = 0.699 for MS. The visual difference is the same as the SPSS and Python images.

The observed difference is 0.225. This means the GP pass proportion is approximately 22.5 percentage points higher than the MS pass proportion.

Because R confirms the same values, it provides strong validation that the result is not a software-specific artifact.

3. R Chart: Confidence Interval for Difference in Proportions

R confidence interval for difference in proportions
R validation chart showing the 95% confidence interval for pGP − pMS.

The R confidence interval chart validates the same interval estimate: [0.160, 0.290]. The point estimate is 0.225.

The interval is entirely above zero, which means the difference is positive in the estimated population. This supports the conclusion that GP has a higher pass proportion than MS.

The R chart also helps communicate the effect size. The school difference is likely not only statistically significant but also meaningful in practical terms.

4. R Chart: Z Statistic on the Standard Normal Curve

R Two Proportion Z Test z statistic standard normal curve
R validation chart showing z = 7.57 on the standard normal curve.

The R standard normal curve chart confirms the formal z-test decision. The observed z statistic is 7.57, far beyond the critical values of ±1.96.

A z value this extreme means the observed difference would be highly unlikely under the null hypothesis of equal pass proportions.

Therefore, the R chart supports the same final decision: reject the null hypothesis and conclude that the two school pass proportions are significantly different.

5. R Chart: Pass/Fail Percentage Composition by School

R pass fail percentage composition by school
R validation chart showing pass/fail percentage composition by school.

The R percentage composition image confirms the same school pattern. GP has a pass share of about 92.4%, while MS has a pass share of about 69.9%.

This chart presents the difference in an easy-to-read percentage format. It makes clear that the failure share is much larger in MS than in GP.

The percentage composition supports the test result by showing why the difference in proportions is large.

6. R Chart: Pass Proportion by Sex Within School

R pass proportion by sex within school for Two Proportion Z Test
R validation chart showing pass proportions by sex within each school.

The R sex-within-school chart confirms the subgroup values. Female students have GP = 96.2% and MS = 71.9%. Male students have GP = 87.6% and MS = 66.3%.

In both sex categories, GP has a higher pass proportion than MS. This supports the descriptive interpretation that the school difference appears across sex groups.

The chart is not a replacement for the main test. It is validation and subgroup context for the overall school comparison.

7. R Chart: Pass Proportion by Study Time Within School

R pass proportion by study time within school for Two Proportion Z Test
R validation chart showing pass proportions by study time within each school.

The R study-time chart confirms the same study-time pattern. GP is higher than MS in every study-time category.

The exact values are: category 1, 84.0% versus 66.7%; category 2, 95.1% versus 68.7%; category 3, 95.8% versus 84.6%; category 4, 100.0% versus 75.0%.

This chart provides useful context, but the final inferential decision remains based on the overall two-proportion z statistic.

Overall Interpretation of All SPSS, Python and R Images

All three software outputs tell the same statistical story. GP has a higher pass proportion than MS. The raw count images show 391/423 passing in GP and 158/226 passing in MS. The proportion images show 0.924 versus 0.699. The confidence interval images show that the difference is positive and does not include zero. The standard normal curve images show that z = 7.57 is far into the rejection region.

Image typeMain messageHow it supports the test
Pass/fail count imagesGP = 391 pass, 32 fail; MS = 158 pass, 68 failProvides x1, n1, x2 and n2.
Pass proportion comparison imagesGP = 0.924 and MS = 0.699Shows the observed group difference.
Confidence interval imagesDifference = 0.225, 95% CI [0.160, 0.290]Shows the difference is above zero.
Z curve imagesObserved z = 7.57Shows the result is far beyond ±1.96.
Percentage composition imagesGP pass share is 92.4%; MS pass share is 69.9%Shows practical percentage difference.
Sex subgroup imagesGP is higher for both female and male studentsProvides descriptive subgroup support.
Study-time subgroup imagesGP is higher in every study-time categoryProvides descriptive context across study habits.

The final decision is consistent across SPSS, Python and R: reject the null hypothesis. The pass proportions are significantly different between GP and MS, and GP has the higher pass proportion.

How to Run Two Proportion Z Test in SPSS, Python, R and Excel

SPSS Method

SPSS can calculate the required counts with crosstabulation, and the z statistic can be computed from the group counts and proportions.

* Two Proportion Z Test in SPSS.
* Success condition: pass_final = 1 if G3 >= 10.

NUMERIC pass_final (F1.0).
COMPUTE pass_final = (G3 >= 10).
VALUE LABELS pass_final
  0 'Fail: G3 < 10'
  1 'Pass: G3 >= 10'.
EXECUTE.

CROSSTABS
  /TABLES=school BY pass_final
  /CELLS=COUNT ROW COLUMN.

* After counts are known:
* GP: x1 = 391, n1 = 423
* MS: x2 = 158, n2 = 226.

COMPUTE x1 = 391.
COMPUTE n1 = 423.
COMPUTE x2 = 158.
COMPUTE n2 = 226.

COMPUTE p1 = x1 / n1.
COMPUTE p2 = x2 / n2.
COMPUTE diff = p1 - p2.
COMPUTE p_pool = (x1 + x2) / (n1 + n2).
COMPUTE se_pool = SQRT(p_pool * (1 - p_pool) * (1/n1 + 1/n2)).
COMPUTE z_value = diff / se_pool.
COMPUTE p_value_two_tailed = 2 * (1 - CDF.NORMAL(ABS(z_value), 0, 1)).
COMPUTE se_unpooled = SQRT((p1 * (1 - p1) / n1) + (p2 * (1 - p2) / n2)).
COMPUTE ci_95_low = diff - 1.96 * se_unpooled.
COMPUTE ci_95_high = diff + 1.96 * se_unpooled.
EXECUTE.

Python Method

Python can calculate the two proportion z test from the two success counts and group sample sizes.

import math

x1, n1 = 391, 423   # GP
x2, n2 = 158, 226   # MS
alpha = 0.05

p1 = x1 / n1
p2 = x2 / n2
diff = p1 - p2

p_pool = (x1 + x2) / (n1 + n2)
se_pool = math.sqrt(p_pool * (1 - p_pool) * (1/n1 + 1/n2))
z_value = diff / se_pool

p_value_two_tailed = math.erfc(abs(z_value) / math.sqrt(2))

se_unpooled = math.sqrt((p1 * (1 - p1) / n1) + (p2 * (1 - p2) / n2))
ci_low = diff - 1.96 * se_unpooled
ci_high = diff + 1.96 * se_unpooled

decision = "Reject H0" if p_value_two_tailed < alpha else "Fail to reject H0"

print("p1:", p1)
print("p2:", p2)
print("Difference:", diff)
print("Pooled p:", p_pool)
print("z:", z_value)
print("p-value:", p_value_two_tailed)
print("95% CI:", ci_low, ci_high)
print("Decision:", decision)

R Method

R can reproduce the same result using direct formulas or a proportion test workflow.

x1 <- 391
n1 <- 423
x2 <- 158
n2 <- 226
alpha <- 0.05

p1 <- x1 / n1
p2 <- x2 / n2
diff <- p1 - p2

p_pool <- (x1 + x2) / (n1 + n2)
se_pool <- sqrt(p_pool * (1 - p_pool) * (1/n1 + 1/n2))
z_value <- diff / se_pool

p_value_two_tailed <- 2 * (1 - pnorm(abs(z_value)))

se_unpooled <- sqrt((p1 * (1 - p1) / n1) + (p2 * (1 - p2) / n2))
ci_low <- diff - 1.96 * se_unpooled
ci_high <- diff + 1.96 * se_unpooled

decision <- ifelse(p_value_two_tailed < alpha, "Reject H0", "Fail to reject H0")

data.frame(
  p1 = p1,
  p2 = p2,
  difference = diff,
  pooled_p = p_pool,
  z_value = z_value,
  p_value = p_value_two_tailed,
  ci_low = ci_low,
  ci_high = ci_high,
  decision = decision
)

Excel Method

Excel can calculate the Two Proportion Z Test using basic formulas. Enter the counts in cells and use formulas for proportions, pooled p, standard error, z statistic, p-value and confidence interval.

Excel itemExample formulaPurpose
GP pass proportion=391/423Calculates p1.
MS pass proportion=158/226Calculates p2.
Difference=p1_cell-p2_cellCalculates p1 − p2.
Pooled proportion=(391+158)/(423+226)Calculates pooled p under H0.
Pooled standard error=SQRT(p_pool*(1-p_pool)*(1/423+1/226))Calculates SE for the z statistic.
Z statistic=difference_cell/se_pool_cellCalculates z.
Two-tailed p-value=2*(1-NORM.S.DIST(ABS(z_cell),TRUE))Calculates p-value.
Unpooled SE for CI=SQRT(p1*(1-p1)/423+p2*(1-p2)/226)Calculates SE for confidence interval.
95% CI lower=difference_cell-1.96*se_unpooled_cellLower confidence bound.
95% CI upper=difference_cell+1.96*se_unpooled_cellUpper confidence bound.

How to Report the Two Proportion Z Test

A complete report should include the two groups, success definition, group counts, sample proportions, difference, z statistic, p-value, confidence interval and decision.

APA-style report: A two proportion z test was conducted to compare final exam pass proportions between GP and MS schools. Pass was defined as G3 ≥ 10. The GP pass proportion was 391/423 = .924, and the MS pass proportion was 158/226 = .699. The difference was statistically significant, z = 7.572, p < .001, 95% CI for pGP − pMS [.160, .290]. Therefore, the null hypothesis of equal pass proportions was rejected. GP had a significantly higher pass proportion than MS.

In plain language, the GP school pass rate was about 92.4%, while the MS school pass rate was about 69.9%. The difference of about 22.5 percentage points is statistically significant and practically meaningful.

Common Mistakes in Two Proportion Z Test Interpretation

1. Using a one proportion z test instead

If there are two groups, use a two proportion z test. A one proportion z test is only for comparing one sample proportion with one benchmark value.

2. Forgetting to pool for the hypothesis test

The hypothesis-test standard error uses the pooled proportion because the null hypothesis says the two population proportions are equal.

3. Using the pooled standard error for the confidence interval

The confidence interval for the difference usually uses the unpooled standard error because it estimates the actual difference between proportions.

4. Reporting p = .000

Do not write p = .000. If the p-value is extremely small, report p < .001.

5. Treating subgroup charts as formal adjusted tests

The sex and study-time charts are descriptive context. They do not replace a formal adjusted model or stratified hypothesis test.

6. Confusing two proportion z test vs chi square

For a 2 × 2 table, the two proportion z test and chi-square test of independence are closely related. The z statistic squared equals the chi-square statistic in the equivalent two-sided 2 × 2 test. For broader categorical analysis, see Cross Tabulation.

FAQs About Two Proportion Z Test

What is a Two Proportion Z Test?

A Two Proportion Z Test is a hypothesis test used to compare two independent sample proportions.

When to use Two Proportion Z Test?

Use it when the outcome is binary and you want to compare two independent groups, such as pass/fail rates for two schools.

What is the Two Proportion Z Test formula?

The formula is z = (p1 − p2) / sqrt[p pooled × (1 − p pooled) × (1/n1 + 1/n2)].

What was the result in this example?

GP had 391 passes out of 423 students, and MS had 158 passes out of 226 students. The difference was 0.225, z = 7.572, p < .001, and 95% CI [0.160, 0.290].

How do you find the p-value for Two Proportion Z Test?

After calculating the z statistic, use the standard normal distribution. For a two-tailed test, p-value = 2 × [1 − Φ(|z|)]. In this example, z = 7.572, so p < .001.

Why do we pool for the Two-Proportion Z-Test?

We pool for the hypothesis test because the null hypothesis assumes the two population proportions are equal. The pooled proportion estimates the common value under H0.

What are the conditions for Two Proportion Z Test?

The outcome must be binary, the groups must be independent, observations should be independent, and expected success/failure counts should be large enough for the normal approximation.

What is the difference between One Proportion Z Test and Two Proportion Z Test?

One Proportion Z Test compares one sample proportion with one benchmark. Two Proportion Z Test compares two sample proportions from two independent groups.

Can I do Two Proportion Z Test in Excel?

Yes. Excel can calculate p1, p2, pooled proportion, standard error, z statistic, p-value and confidence interval using ordinary formulas.

Is Two Proportion Z Test the same as chi-square?

For a 2 × 2 table, the two-sided two proportion z test is closely related to the chi-square test of independence. The z statistic squared equals the chi-square statistic for the equivalent 2 × 2 comparison.

Advertisement
Google AdSense bottom placement reserved here

Need help applying this to your own data?

Salar Cafe can help interpret output, clean datasets, review assumptions, build dashboards and explain statistical results ethically.

Need help interpreting your data analysis results?

Contact Salar Cafe
Engr. Muhammad Yar Saqib author profile photo

Engr. Muhammad Yar Saqib

WhatsApp Get Data Analysis Help