EProportions · Guide test 056
Two proportion score z test
Tests equality of independent proportions using a pooled null estimate.
Do it in CodeSplash
In the app, set it up in Analyze with this method:
- Two independent proportions (z, Fisher, Boschloo, Barnard, non-inferiority) — Does the share of an outcome differ between two independent groups?
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
Alternative
The statistic's distribution if the design's true effect is real.
Your data
Edit the countsIf H₀ were true
- The reference: how z varies across samples when H₀ is true.
- Your statistic, from the data above.
- The p-value: the area at least as extreme as yours (p = .040).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- the observed proportions
- the pooled proportion (assumes H₀)
- 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 H₀.
Question and hypotheses
H0: p1=p2.
Assumptions
Two independent binomial samples with adequate expected counts for normal calibration.
Formula
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.
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))
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
- statsmodels — statsmodels · stats.proportion.proportions_zteststatsmodels.org
- statsmodels.stats.proportion.proportions_zteststatsmodels.org
- 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.