Menu

Inputs

Calculate Sample Size Needed to Compare Paired Proportions: McNemar's Z-test, 1-Sided

This calculator is useful for tests comparing paired proportions. Suppose that our sample consists of pairs of subjects, and that each pair contains a subject from group 'A' and a subject from group 'B'. Further suppose that we wish to compare the probability that an event occurs in group 'A' to that in group 'B'. Example study designs include matched case-control studies and cross-over studies. Conceptually, the data can be listed as in the following table.
GroupBSuccessFailureGroupASuccessn11n10Failuren01n00\begin{array}{cc|cc} & & {Group \quad 'B'} \\ & & Success & Failure \\ \hline Group \quad 'A' & Success & n_{11} & n_{10} \\ & Failure & n_{01} & n_{00} \end{array}
Here, nijn_{ij} represents the number of pairs having ii successes in Group 'A' and jj successes in Group 'B'. The corresponding proportions are denoted pijp_{ij}, with table
GroupBSuccessFailureGroupASuccessp11p10Failurep01p00\begin{array}{cc|cc} & & {Group \quad 'B'} \\ & & Success & Failure \\ \hline Group \quad 'A' & Success & p_{11} & p_{10} \\ & Failure & p_{01} & p_{00} \end{array}
Interest is in comparing the following hypotheses: H0H_0: Both groups have the same success probability H1H_1: The success probability is greater for one group than the other Mathematically, this can be represented as
H0:p10=p01H_0: p_{10} = p_{01}
H1:p10<p01H_1: p_{10} < p_{01}
or
H0:p10=p01H_0: p_{10} = p_{01}
H1:p10>p01H_1: p_{10} > p_{01}
In the formulas below, we use the notation that
pdisc=p10+p01p_{disc} = p_{10} + p_{01}
and
pdiff=p10p01p_{diff} = p_{10} - p_{01}

Formulas

This calculator uses the following formulas to compute sample size and power, respectively:
n=(z1αpdisc+z1βpdiscpdiff2pdiff)2n = \left( \frac{z_{1-\alpha} \sqrt{p_{disc}} + z_{1-\beta} \sqrt{p_{disc} - p_{diff}^2}}{p_{diff}} \right)^2
1β=Φ(pdiffnz1αpdiscpdiscpdiff2)1-\beta = \Phi \left( \frac{|p_{diff}| \sqrt{n} - z_{1-\alpha} \sqrt{p_{disc}}}{\sqrt{p_{disc} - p_{diff}^2}} \right)
where: nn is sample size Φ\Phi is the standard Normal distribution function Φ1\Phi^{-1} is the standard Normal quantile function α\alpha is Type I error β\beta is Type II error, meaning 1β1-\beta is power

R Code

1p01=0.45
2p10=0.05
3alpha=0.05
4beta=0.20
5pdisc=p10+p01
6pdiff=p10-p01
7(n=((qnorm(1-alpha)*sqrt(pdisc)+qnorm(1-beta)*sqrt(pdisc-pdiff^2))/pdiff)^2)
8ceiling(n) # 23
9x=(abs(pdiff)*sqrt(n)-qnorm(1-alpha)*sqrt(pdisc))/sqrt(pdisc-pdiff^2);
10(Power = pnorm(x))

References

Connor R. J. 1987. Sample size for testing differences in proportions for the paired-sample design. Biometrics 43(1):207-211. page 209.