Biostatistics Study NotesFrom concepts and derivations to interpretation

CHAPTER 05 · TOPIC 07

McNemar’s Test

Analyze discordant pairs in paired binary data to compare directional change probabilities and marginal proportions.

On this page
  1. Paired 2×2 Table
  2. Hypothesis and conditional binomial distribution
  3. Derivation of the Z Statistic
  4. McNemar chi-square statistic
  5. Exact McNemar test
  6. Continuity correction
  7. Difference with independence test
  8. Implementation and reporting procedures

The McNemar test tests whether marginal proportions are equal in paired binary data, such as before and after measurements of the same subject or matched pairs. Unlike a regular 2x2 independence test, only the unmatched pairs that have changed results are informative.

Paired 2×2 Table#

Measurement 1\Measurement 2positivenegative
positivea: Positive → Positiveb: Positive → Negative
negativec: Negative → positived: Negative → negative

a and d are unchanged matched pairs. b and c are mismatched pairs that change in opposite directions, and H₀ asserts that these two directions occur to the same extent.

Hypothesis and conditional binomial distribution#

null hypothesisH0:Pb=PcH_0:P_b=P_c
alternative hypothesisH1:PbPcH_1:P_b\ne P_c
Limited to mismatched pairsH0:π=P(bb or c)=12H_0:\pi=P(b\mid b\text{ or }c)=\frac12
Total number of mismatched pairsn=b+cn=b+c
Distribution under H₀B(B+C=n)Binomial(n,12)B\mid(B+C=n)\sim\operatorname{Binomial}\left(n,\frac12\right)

Derivation of the Z Statistic#

Mean and variance under H₀E(B)=n2,Var(B)=n4E(B)=\frac n2,\qquad\operatorname{Var}(B)=\frac n4
standardizationZ=bn/2n/4Z=\frac{b-n/2}{\sqrt{n/4}}
Assign n=b+cZ=b(b+c)/2(b+c)/4Z=\frac{b-(b+c)/2}{\sqrt{(b+c)/4}}
simplificationZ=bcb+cZ=\frac{b-c}{\sqrt{b+c}}

McNemar chi-square statistic#

χM2=Z2=(bc)2b+c,df=1\chi_M^2=Z^2=\frac{(b-c)^2}{b+c},\qquad df=1

For a two-sided test, you can use χ², which is Z squared. The larger the difference between b and c compared to the total number of mismatched pairs, the more contrary to H₀ that the marginal ratios are equal.

Exact McNemar test#

pexact=2min{P(Bbobs), P(Bbobs)}(upper limit 1)p_{\mathrm{exact}}=2\min\left\{P(B\leq b_{\mathrm{obs}}),\ P(B\geq b_{\mathrm{obs}})\right\}\quad\text{(upper limit 1)}

If b+c is small, use B~Binomial(b+c,1/2) directly. Since it is a discrete distribution, specify the definition of a two-sided p value and whether to use mid-p.

Continuity correction#

Correction ZZY=bc1b+cZ_Y=\frac{|b-c|-1}{\sqrt{b+c}}
Corrected McNemar statisticχM,Y2=(bc1)2b+c\chi_{M,Y}^2=\frac{\left(|b-c|-1\right)^2}{b+c}

If you subtract 0.5 on the binomial scale of b, you subtract 1 on the b - c difference scale. Although the correction is more conservative, the exact binomial method is more direct for small numbers of discrepancies.

Difference with independence test#

itemPearson independence testMcNemar test
dataTwo binary variables from independent observationsBinary results with matched and repeated measurements
H₀two variables are independentThe two discordant transition probabilities, or marginal proportions, are equal
Cell to useall cellsMismatched cells b, c
large sample statisticsΣ(O−E)²/E(b−c)²/(b+c)

Implementation and reporting procedures#

  1. Check the definition of pairs and encoding of binary results
  2. Make a, b, c, d and check especially the number of discrepancies b+c
  3. Preset H₀, bilateral/unilateral, α
  4. If the number of discrepancies is sufficient, select uncorrected or corrected χ², if small, select exact binomial method.
  5. b and c, report proportions, changes, p-values, and usage for each time point
  6. Consider the impact of missing data and dropped pairs on the results