The tests are equivalent. They both test the same null hypothesis $H_0: p_1 = p_2$, versus $H_1: p_1 \ne p_2$ (for the two-sided case).
In the two-sample binomial test, we assume a Normal approximation and test the statistic
$$Z = \frac{\hat p_1 - \hat p_2}{\sqrt{\hat p (1 - \hat p)( 1 /n_1 + 1 / n_2 )}} \sim N(0, 1)$$
The denominator is the pooled standard error, with $p$ estimated by the weighted average of $\hat p_1$ and $\hat p_2$:
$$\hat p = \frac{n_1 \hat p_1 + n_2 \hat p_2}{n_1 + n_2} = \frac{x_1 + x_2}{n_1 + n_2}$$
In the 2x2 contingency table method, we again assume the Normal approximation and test the statistic
$$X^2 = \sum_{i=1}^2 \sum_{j=1}^2 \frac{(O_{ij} - E_{ij})^2}{E_{ij}} \sim \chi^2_1$$
The mathematical justification for the chi-square distribution is based on the idea of summing "z-scores" of each cell's observed versus expected count.
The resulting p-values should be identical, since by definition $\chi^2_1 = Z^2$.
Ref. Section 10.2 of Fundamentals of Biostatistics, 3ed (1990) by Bernard Rosner.
Before I knew about prop.test()
, I implemented the two-sample pooled-variance binomial (approximation) z-test from NIST Engineering Statistics Handbook. This uses the pooled standard error $\sqrt{\hat p (1 - \hat p) ( 1 / n_1 + 1 / n_2 ) } $, since under the null hypothesis, $p_1 \sim N(p, p(1-p)/n_1)$ and $p_2 \sim N(p, p(1-p)/n_2)$, and $p$ is estimated by the weighted average $\hat p$ given above.
> bin_test <- function(x1, n1, x2, n2) {
p1 <- x1 / n1
p2 <- x2 / n2
p <- (x1 + x2) / (n1 + n2)
z <- (p2 - p1) / sqrt(p*(1-p)*(1/n1 + 1/n2))
z
}
> bin_test(474, 750, 376, 750)^2
[1] 26.07421
> prop.test(x = c(474, 376), n = c(750, 750))
2-sample test for equality of proportions with continuity correction
data: c(474, 376) out of c(750, 750)
X-squared = 25.545, df = 1, p-value = 4.322e-07
alternative hypothesis: two.sided
95 percent confidence interval:
0.07961695 0.18171638
sample estimates:
prop 1 prop 2
0.6320000 0.5013333
The statistic is close, but slightly more conservative in p-value. The R docs says Yates's continuity correction is applied by default. If you turn that off, the result is exact:
> prop.test(x = c(474, 376), n = c(750, 750), correct=FALSE)
2-sample test for equality of proportions without continuity correction
data: c(474, 376) out of c(750, 750)
X-squared = 26.074, df = 1, p-value = 3.285e-07
alternative hypothesis: two.sided
95 percent confidence interval:
0.08095028 0.18038305
sample estimates:
prop 1 prop 2
0.6320000 0.5013333
prop.test
,chisq.test
and z-test on your data then they all give you the same p-value = 3.285e-07. All tests should be conducted without continuity correction. $\endgroup$