The two-proportion Z-test (also called the two-sample proportion Z-test) is a statistical hypothesis test for assessing whether two groups differ in the proportion of a binary outcome, in such a significant way that is beyond chance. For example, the proportion of patients responding positively to a treatment in a clinical trial versus control, the defect rate in quality control for two production lines, or the click-through rate in an A/B test of two alternative webpage designs.

The test is appropriate when each observation is independent from another, can be classified as a success or failure (i.e., a Bernoulli trial) and the sample sizes are large enough that the sampling distribution of each sample proportion is well approximated by the central limit theorem. Under those conditions the observed difference of sample proportions can be converted to a standardized z-statistic (using a pooled standard error) and compared to the standard normal distribution to obtain p-values or form confidence intervals for the difference in proportions (derived slightly differently). This also allows to determine required sample-size for a minimum-detectable-effect calculations.

The test is related to other well known tests such as Pearson's chi-squared test, Fisher's exact test for small samples, and McNemar's test for paired binary data.

Definition The two-proportion Z-test or two-sample proportion Z-test is a statistical method used to determine whether the difference between the proportions of two groups, coming from a binomial distribution is statistically significant.Hypothesis Test: Difference Between Proportions This approach relies on the observation that (for a sufficiently large samples) the sample proportions follow a normal distribution under the Central Limit Theorem, allowing the construction of a z-test for hypothesis testing (a Score test) and confidence interval estimation (a Wald test). It is used in various fields to compare success rates, response rates, or other proportions across different groups.

Hypothesis test The z-test for comparing two proportions is a frequentist statistical hypothesis test used to evaluate whether two independent samples have different population proportions for a binary outcome. Under mild regularity conditions (sufficiently large sample sizes and independent sampling), the sample proportions (which is the average of observations coming from a Bernoulli distribution) are approximately normally distributed under the central limit theorem, which permits using a z-statistic constructed from the difference of sample proportions and an estimated standard error.

The test involves two competing hypotheses: null hypothesis (H0): The proportions in the two populations are equal, i.e., . alternative hypothesis (H1): The proportions in the two populations are not equal, i.e., (two-tailed) or / (one-tailed).

The z-statistic for comparing two proportions is computed using:where and are the sample proportion in the first and second sample, and are the size of the first and second sample, respectively, is pooled proportion, calculated as , where and are the counts of successes in the two samples The pooled proportion is used to estimate the shared probability of success under the null hypothesis, and the standard error accounts for variability across the two samples.

The z-test determines statistical significance by comparing the calculated z-statistic to a critical value. E.g., for a significance level of we reject the null hypothesis if (for a two-tailed test). Or, alternatively, by computing the p-value and rejecting the null hypothesis if .

Confidence interval The confidence interval for the difference between two proportions, based on the definitions above, is:where is the critical value of the standard normal distribution (e.g., 1.96 for a 95% confidence level).

This interval provides a range of plausible values for the true difference between population proportions.

Notice how the variance estimation is different between the hypothesis testing and the confidence intervals. The first uses a pooled variance (based on the null hypothesis), while the second has to estimate the variance using each sample separately (so as to allow for the confidence interval to accommodate a range of differences in proportions). This difference may lead to slightly different results if using the confidence interval as an alternative to the hypothesis testing method.

Sample size determination and Minimum detectable effect Sample size determination is the act of choosing the number of observations to include in each group for running the statistical test. For the Two-proportion Z-test, this is closely-related with deciding on the minimum detectable effect.

For finding the required sample size (given some effect size , power , and type I error ), we define that , (when κ = 1, equal sample size is assumed for each group), then:

The minimum detectable effect or MDE is the smallest difference between two proportions ( and ) that a statistical test can detect for a chosen type I error level (), statistical power (), and sample sizes ( and ). It is commonly used in study design to determine whether the sample sizes allows for a test with sufficient sensitivity to detect meaningful differences.

The MDE for when using the (two-sided) z-test formula for comparing two proportions, incorporating critical values for and , and the standard errors of the proportions:COOLSerdash (https://stats.stackexchange.com/users/21054/coolserdash), Two proportion sample size calculation, URL (version: 2023-04-14): https://stats.stackexchange.com/q/612894where is critical value for the significance level, is quantile for the desired power, and is when assuming the null is correct.

The MDE depends on the sample sizes, baseline proportions (), and test parameters. When the baseline proportions are not known, they need to be assumed or roughly estimated from a small study. Larger samples or smaller power requirements leads to a smaller MDE, making the test more sensitive to smaller differences. Researchers may use the MDE to assess the feasibility of detecting meaningful differences before conducting a study.

The Minimal Detectable Effect (MDE) is the smallest difference, denoted as , that satisfies two essential criteria in hypothesis testing:

The null hypothesis () is rejected at the specified significance level (). Statistical power () is achieved under the alternative hypothesis ().

Given that the distribution is normal under the null and the alternative hypothesis, for the two criteria to happen, it is required that the distance of will be such that the critical value for rejecting the null () is exactly in the location in which the probability of exceeding this value, under the null, is (), and also that the probability of exceeding this value, under the alternative, is .

The first criterion establishes the critical value required to reject the null hypothesis. The second criterion specifies how far the alternative distribution must be from to ensure that the probability of exceeding it under the alternative hypothesis is at least .Calculating Sample Sizes for A/B TestsPower, minimal detectable effect, and bucket size estimation in A/B tests (has some nice figures to illustrate the tradeoffs)

Condition 1: Rejecting

Under the null hypothesis, the test statistic is based on the pooled standard error ():

might be estimated (as described above).

To reject , the observed difference must exceed the critical threshold () after properly inflating it to the SE:

If the MDE is defined solely as , the statistical power would be only 50% because the alternative distribution is symmetric about the threshold. To achieve a higher power level, an additional component is required in the MDE calculation.

Condition 2: Achieving power

Under the alternative hypothesis, the standard error is (). It means that if the alternative distribution was centered around some value (e.g., ), then the minimal must be at least larger than to ensure that the probability of detecting the difference under the alternative hypothesis is at least .

Combining conditions

To meet both conditions, the total detectable difference incorporates components from both the null and alternative distributions. The MDE is defined as:

By summing the critical thresholds from the null and adding to it the relevant quantile from the alternative distributions, the MDE ensures the test satisfies the dual requirements of rejecting at significance level and achieving statistical power of at least .

Assumptions and conditions To ensure valid results, the following assumptions must be met: Independent random samples: The samples must be drawn independently from the populations of interest. Large sample sizes: Typically, should exceed 20. Success or failure condition:Course notes for STAT 200: Elementary Statistics. 9.1 - Two Independent Proportions, Penn State's Department of Statistics and and

The z-test is most reliable when sample sizes are large, and all assumptions are satisfied.

Relation to other statistical methods Related tests Using the z-test for hypothesis testing (Score test) would give the same results as Pearson's chi-squared test for a two-by-two contingency table. Fisher's exact test is more suitable for when the sample sizes are small.

Treatment of 2-by-2 contingency table has been investigated as early as the 19th century, with further work during the 20th century.

Notice that: When one or more cell counts are small (e.g. below 5), prefer exact tests (e.g., Fisher's exact test) or exact confidence intervals. For paired or matched binary data use McNemar's test rather than the two-sample z-test.   The choice between pooled and unpooled variance matters: pooled variance is appropriate for hypothesis testing of equality (), whereas the unpooled variance is used for confidence intervals.   Multiple testing, selection effects, and nonrandom sampling can invalidate p-values and CIs; these design issues should be addressed in the study methods.

In Bayesian inference context, proportions can be modeled using the Beta distribution. The parallel to two proportion z-test is performing similar inference using the difference of two Beta distributions.Chen, Y., & Luo, S. (2011). A few remarks on 'Statistical distribution of the difference of two proportions' by Nadarajah and Kotz, Statistics in Medicine 2007; 26 (18): 3518-3523. Statistics in Medicine, 30(15), 1913-1915.

Newcombe's method The standard asymptotic confidence interval (Wald interval) for the difference between proportions can suffer from poor coverage probabilities, particularly when the sample sizes are small or the proportions are close to 0 or 1. Additionally, the Wald method can sometimes produce "overshoot" limits that extend beyond the meaningful [−1, 1] range. To address this, Robert G. Newcombe proposed a highly robust alternative method based on the Wilson score interval.

Newcombe's method computes the confidence interval for the difference by first calculating these individual score intervals for each sample proportion independently. Let be the lower and upper bounds for , and be the lower and upper bounds for . The interval bounds for a given sample proportion with sample size are calculated as:

where is the critical value from the standard normal distribution (e.g., 1.96 for a 95% confidence level).

Once the individual bounds are calculated, the lower limit and upper limit for the difference between the two proportions are constructed as follows:

This method is frequently recommended over the traditional Wald method because its resulting interval is strictly bounded between −1 and 1, and it aligns much more closely with the nominal confidence level without requiring a continuity correction.

Example