Skip to content

EProportions · Guide test 056

Two proportion score z test

Tests equality of independent proportions using a pooled null estimate.

Runs in CodeSplashPython example validatedR example validated

Do it in CodeSplash

In the app, set it up in Analyze with this method:

Do it in CodeSplash Run this test on your own data, in Python or R.

Bench

Change the design, drag the data, move α. The statistic, its reference distribution and the verdict follow.

Bench · Two-proportion score z test

60
60
0.45
0.30
0.050

Alternative

The statistic's distribution if the design's true effect is real.

Your data

Edit the counts
Group 129 of 60 · 0.483
Group 218 of 60 · 0.300

If H₀ were true

z = 2.06
  1. The reference: how z varies across samples when H₀ is true.
  2. Your statistic, from the data above.
  3. The p-value: the area at least as extreme as yours (p = .040).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

z=p^1−p^2pˉ(1−pˉ)(1/n1+1/n2)z = \dfrac{\hat p_1-\hat p_2}{\sqrt{\bar p(1-\bar p)(1/n_1+1/n_2)}}

With your numbers

z=0.48−0.300.39(1−0.39)(1/60+1/60)=2.06z = \dfrac{0.48 - 0.30}{\sqrt{0.39(1-0.39)(1/60+1/60)}} = 2.06
p^1,p^2\hat p_1, \hat p_2
the observed proportions
pˉ\bar p
the pooled proportion (assumes H₀)
n1,n2n_1, n_2
the group sizes

The verdict

χ² = 4.23, z = 2.06, p = .040, Δp = 0.18

p ≤ α = .050: reject H₀

Effect size: difference in proportions Δp = 0.183

Pooling under H0 gives the score test; z² equals the χ² statistic of the 2 × 2 table. Expected counts below 5 call for an exact test.

Statistic
2.057
p-value
0.0397
Two-proportion score z test on 29/60 vs 18/60: χ² = 4.23, z = 2.06, p = .040, Δp = 0.18. The p-value is below α = .050, so the data are hard to reconcile with H0.

Two-proportion score z test on 29/60 vs 18/60: χ² = 4.23, z = 2.06, p = .040, Δp = 0.18. The p-value is below α = .050, so the data are hard to reconcile with H₀.

Question and hypotheses

H0: p1=p2.

Assumptions

Two independent binomial samples with adequate expected counts for normal calibration.

Formula

p^=x1+x2n1+n2z=x1/n1−x2/n2p^(1−p^)(1/n1+1/n2)\begin{gathered}\widehat p=\frac{x_1+x_2}{n_1+n_2}\\[5pt] z=\frac{x_1/n_1-x_2/n_2}{\sqrt{\widehat p(1-\widehat p)(1/n_1+1/n_2)}}\end{gathered}

Parameters and notation

xi successes in ni trials. Pooling estimates the common probability under H0.

Structure of the method

Two independently sampled binomial counts enter a pooled-null score contrast. Pool successes across both groups to estimate the common probability, standardize the observed proportion difference, and obtain a normal tail. Squaring z reproduces uncorrected Pearson inference for the corresponding 2-by-2 table.

Estimated and nuisance parameters

Estimate both group proportions for interpretation and one pooled proportion under the equality null for variance. Group sizes are fixed by design or conditioned upon. A nonzero hypothesized difference changes the constrained nuisance fit; the displayed equality formula cannot simply subtract an arbitrary delta.

Settings and design choices

Choose alternative direction, continuity correction, confidence level, and effect scale before inspection. Report a difference, ratio, or odds ratio with an interval appropriate to that target. Multiplicity across several group comparisons requires an explicit family and correction.

Fitting and adaptation

Refit the pooled probability whenever observations or group definitions change. For a simulation check under equality, generate two binomial counts with the observed sample sizes and a common probability. Preserve pairing or clustering by switching to a method designed for that structure.

Sensitivity and robustness

Near-zero or near-one probabilities and imbalanced group sizes reduce the quality of normal calibration. Complete success or failure in both groups makes the pooled variance degenerate. Exact alternatives still require correct independent-binomial sampling; they do not repair dependence.

How to use and calibrate

Use a normal tail; z² equals the uncorrected 2×2 Pearson independence statistic.

Example application

Compare response rates between independently randomized arms.

Interpretation and pitfalls

Watch out

Paired binary responses require McNemar. A nonzero null difference requires a constrained probability fit, not this simple pooling formula.

What changed in edition 2

  • New sections: structure of the method, estimated and nuisance parameters, settings and design choices, fitting and adaptation, sensitivity and robustness.

Python and R

Pooled null variance tests equality of independent proportions; counts are successes and nobs are denominators.

Python · native

Validated — Executed successfully in the validation environment · needs numpy, scipy, statsmodels

import numpy as np
from scipy import stats
rng = np.random.default_rng(2026)
from statsmodels.stats.proportion import proportions_ztest
print(proportions_ztest([18,9],[30,30]))
Output
(np.float64(2.3354968324845684), np.float64(0.019517481182177766))
R

Validated — Executed successfully in the validation environment · needs Base/standard library

print(prop.test(c(18,9),c(30,30),correct=FALSE))
Output
	2-sample test for equality of proportions without continuity correction

data:  c(18, 9) out of c(30, 30)
X-squared = 5.4545, df = 1, p-value = 0.01952
alternative hypothesis: two.sided
95 percent confidence interval:
 0.05995442 0.54004558
sample estimates:
prop 1 prop 2 
   0.6    0.3

Sources

Statistics guide v4 (historical):
Python: Executed successfully in the validation environment · R: Executed successfully in the validation environment
Reference's record:
Edition 2 review: Python: skip · R: not executed (Rscript unavailable); why not run: Python: Unavailable local dependencies: statsmodels. Python: Not run in the reference's review: Unavailable local dependencies: statsmodels. No installation attempted. R: Reviewed but not run: R wasn't available to the reference's authors.

From the CodeSplash statistics guide (v4), entry 056, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT056.