---
title: "McNemar’s test in R"
url: https://daily.dev/posts/mcnemar-s-test-in-r-muzqqzd1b
source_url: https://www.r-bloggers.com/2026/08/mcnemars-test-in-r
type: article
source: "R-bloggers"
published: 2026-08-19T13:58:35.716Z
updated: 2026-08-19T14:05:03.150Z
tags: ["data-science", "r", "statistics"]
reading_time: 13
upvotes: 0
comments: 0
language: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# McNemar’s test in R

**[R-bloggers](https://daily.dev/sources/rbloggers)** · 13 min read · 0 upvotes · 0 comments

## Summary

A walkthrough of McNemar's test for comparing two related proportions measured on paired, dependent samples (e.g., the same subjects before and after an intervention). It covers how to build the 2x2 contingency table of paired outcomes, the hypotheses and assumptions (paired binary data, independent pairs, enough discordant pairs), and how to run the test in R using mcnemar.test(), with and without continuity correction, plus the exact binomial alternative via binom.test() for small samples. A simulated example of opinions before/after a public debate demonstrates the full workflow and interpretation of results.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.r-bloggers.com/2026/08/mcnemars-test-in-r>

## Questions this post answers

### How do I run McNemar's test in R on paired before/after survey data?

Build a 2x2 contingency table of the paired responses with table(), then pass it to mcnemar.test(). By default R applies a continuity correction; add correct = FALSE to remove it. The function returns a chi-squared statistic, 1 degree of freedom, and a p-value, or you can call mcnemar.test() directly on the two paired vectors instead of the table.

_daily.dev surfaces R and statistics walkthroughs like this for anyone analyzing paired data._

### When should I use McNemar's test instead of a chi-square test of independence?

Use McNemar's test when the two measurements are collected on the same subjects (paired samples), such as before/after an intervention, since the chi-square test of independence assumes independent observations. McNemar's test relies only on the discordant pairs, comparing how many subjects switched in each direction, while concordant pairs (no change) carry no information about the effect.

_Developers choosing the right statistical test can track comparisons like this on daily.dev._

### How many discordant pairs are needed for McNemar's chi-square approximation to be valid?

A common rule of thumb is that the sum of the two discordant cells (b+c) should be at least 25 for the chi-square approximation used by mcnemar.test() to be reliable. Below that threshold, use the exact version based on the binomial distribution instead, via binom.test() or the mcnemar.exact() function from the exact2x2 package.

_daily.dev keeps practical R statistics guidance like this within reach for data analysis work._

## Similar posts on daily.dev

- [Correcting for multiplicity in the ’emmeans’ package](https://daily.dev/posts/correcting-for-multiplicity-in-the-emmeans-package-yqrlcgptx) · R-bloggers · 0 upvotes · 0 comments
- [Part V – Using R in Excel – Inferential Statistics](https://daily.dev/posts/part-v-using-r-in-excel-inferential-statistics-xiw4hycoz) · R-bloggers · 0 upvotes · 0 comments
- [Distribution of p-values under the null hypothesis for discrete data by @ellis2013nz](https://daily.dev/posts/distribution-of-p-values-under-the-null-hypothesis-for-discrete-data-by-ellis2013nz-rmlmjzusq) · R-bloggers · 0 upvotes · 0 comments

---

Tags: [#data-science](https://daily.dev/tags/data-science), [#r](https://daily.dev/tags/r), [#statistics](https://daily.dev/tags/statistics)

[View this post on daily.dev](https://daily.dev/posts/mcnemar-s-test-in-r-muzqqzd1b)
