StatsCalculators.com

Two Proportion Z-Test

This Two Proportion Z-Test Calculator helps you compare proportions from two independent groups. For example, you could test if the success rates between two different manufacturing processes differ, or if treatment outcomes vary between two groups. The calculator performs comprehensive statistical analysis including hypothesis testing and generates publication-ready reports. Enter the number of successes and total trials for each group below to begin the analysis. Click here to populate the sample data for a quick example.

Calculator

Input Your Values

Yates' continuity correction improves accuracy for discrete data. Learn more

Learn More

Two-Proportion Z-Test

Definition

Two-Proportion Z-Test is used to test if there is a significant difference between two population proportions. It's commonly used when comparing success rates, prevalence, or percentages between two groups.

Formula

Test Statistic:

z=p^1p^2p^(1p^)(1n1+1n2)z = \frac{\hat{p}_1 - \hat{p}_2}{\sqrt{\hat{p}(1-\hat{p})(\frac{1}{n_1} + \frac{1}{n_2})}}

Where:

  • p^1,p^2\hat{p}_1, \hat{p}_2 = sample proportions
  • n1,n2n_1, n_2 = sample sizes
  • p^=x1+x2n1+n2\hat{p} = \frac{x_1 + x_2}{n_1 + n_2} = pooled proportion
  • x1,x2x_1, x_2 = number of successes

Confidence Interval:

Two-sided: CI=(p^1p^2)±zα/2p^1(1p^1)n1+p^2(1p^2)n2\text{Two-sided: }CI = (\hat{p}_1 - \hat{p}_2) \pm z_{\alpha/2}\sqrt{\frac{\hat{p}_1(1-\hat{p}_1)}{n_1} + \frac{\hat{p}_2(1-\hat{p}_2)}{n_2}}One-sided: CI=(p^1p^2)±zαp^1(1p^1)n1+p^2(1p^2)n2\text{One-sided: }CI = (\hat{p}_1 - \hat{p}_2) \pm z_{\alpha}\sqrt{\frac{\hat{p}_1(1-\hat{p}_1)}{n_1} + \frac{\hat{p}_2(1-\hat{p}_2)}{n_2}}

Key Assumptions

Independence: Samples must be independent
Random Sampling: Both samples should be random
Sample Size:Both npnp and n(1p)n(1-p) should be 10\geq 10

Practical Example

Testing effectiveness of two different marketing campaigns:

  • Campaign A: 45 conversions out of 100 views
  • Campaign B: 35 conversions out of 100 views
  • H0:p1=p2H_0: p_1 = p_2 (equal proportions)
  • Ha:p1p2H_a: p_1 \neq p_2 (different proportions)

Calculating z-statistic:

Pooled proportion: p^=45+35200=0.40\hat{p} = \frac{45 + 35}{200} = 0.40

Z-statistic: z=0.450.350.40(0.60)(2100)=1.44z = \frac{0.45 - 0.35}{\sqrt{0.40(0.60)(\frac{2}{100})}} = 1.44

Confidence Interval: CI=(0.450.35)±1.960.45(0.55)100+0.35(0.65)100=[0.035,0.235]CI = (0.45 - 0.35) \pm 1.96\sqrt{\frac{0.45(0.55)}{100} + \frac{0.35(0.65)}{100}} = [-0.035, 0.235]

At 5% significance level, critical value is zα/2=1.96z_{\alpha/2} = 1.96

and pp-value = 0.1500.150. Since pp-value >0.05\gt 0.05, we fail to reject the null hypothesis. There is no significant difference between the two campaigns. We are 95% confident that the true difference in conversion rates is between -3.5% and 23.5%.

Effect Size

Cohen's h measures the difference between two proportions:

h=2arcsinp12arcsinp2h = 2\arcsin\sqrt{p_1} - 2\arcsin\sqrt{p_2}

Interpretation guidelines:

  • Small effect: h0.2|h| \approx 0.2
  • Medium effect: h0.5|h| \approx 0.5
  • Large effect: h0.8|h| \approx 0.8

Code Examples

R
x <- c(45, 35)  # Successes in each group
n <- c(100, 100)  # Number of trials in each group

# Perform two-proportion test
result <- prop.test(
  x = x,
  n = n,
  alternative = "two.sided",
  correct = FALSE  # No continuity correction
)

# Print results
print(result)
Python
from statsmodels.stats.proportion import proportions_ztest
import numpy as np
from scipy import stats

# Example data
success1, n1 = 45, 100
success2, n2 = 35, 100 
p1 = success1 / n1
p2 = success2 / n2

# Perform two-proportion z-test
zstat, pvalue = proportions_ztest(
    [success1, success2],    # Number of successes in each group
    [n1, n2],                # Number of observations in each group
    alternative='two-sided',
)

print(f'z-statistic: {zstat:.4f}')
print(f'p-value: {pvalue:.4f}')

# construct confidence interval
alpha = 0.05
z_critical = stats.norm.ppf(1 - alpha / 2)
margin_of_error = z_critical * np.sqrt((p1 * (1 - p1) / n1) + (p2 * (1 - p2) / n2))
prop_diff = p1 - p2
ci_lower = prop_diff - margin_of_error
ci_upper = prop_diff + margin_of_error
print(f'Confidence interval: ({ci_lower:.4f}, {ci_upper:.4f})')

Alternative Tests

Consider these alternatives:

  • Fisher's Exact Test: For small sample sizes
  • Chi-square Test: For categorical data analysis

Verification

Related Calculators