---
title: "Cochran’s Q test in R, or the extension of McNemar’s test for more than two groups"
url: https://daily.dev/posts/cochran-s-q-test-in-r-or-the-extension-of-mcnemar-s-test-for-more-than-two-groups-usp4hlaey
source_url: https://www.r-bloggers.com/2026/08/cochrans-q-test-in-r-or-the-extension-of-mcnemars-test-for-more-than-two-groups
type: article
source: "R-bloggers"
published: 2026-08-26T15:26:20.525Z
updated: 2026-08-26T16:13:13.123Z
tags: ["r", "data-analysis", "statistics"]
reading_time: 15
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.

# Cochran’s Q test in R, or the extension of McNemar’s test for more than two groups

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

## Summary

Explains Cochran's Q test, the extension of McNemar's test for comparing three or more related (dependent) binary proportions measured on the same subjects. Walks through simulating a repeated-measures survey dataset in R, computing descriptive proportions, running cochran_qtest() from the rstatix package, verifying the mathematical equivalence to McNemar's test when k=2, and following up a significant result with pairwise McNemar's tests adjusted via the Holm method to identify which time points differ.

## 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/cochrans-q-test-in-r-or-the-extension-of-mcnemars-test-for-more-than-two-groups>

## Questions this post answers

### How do I run Cochran's Q test in R for comparing three or more related proportions?

Use the cochran_qtest() function from the rstatix package on data in long format, with a formula of the form outcome ~ condition | subject. For example, dat_long %>% cochran_qtest(opinion ~ time | respondent) returns the test statistic, degrees of freedom, and p-value. The CochranQTest() function from the DescTools package is an alternative.

_daily.dev surfaces R statistics tutorials like this for analysts comparing repeated-measures data._

### What is the difference between McNemar's test and Cochran's Q test?

Cochran's Q test is the extension of McNemar's test to more than two related measurements; McNemar's test handles exactly two paired binary measurements, while Cochran's Q handles three or more. Mathematically, Cochran's Q reduces exactly to McNemar's test when k=2, producing identical test statistics and p-values, provided the continuity correction is removed with correct=FALSE.

_Developers choosing the right paired-sample test can track these statistical comparisons on daily.dev._

### How do I determine which time points differ after a significant Cochran's Q test result?

Perform post-hoc pairwise McNemar's tests on each pair of measurements using pairwise_mcnemar_test() from rstatix, adjusting p-values for multiple comparisons with a method like Holm. In a three-timepoint example, this revealed that support for a policy increased significantly right after a debate (p<0.001), decreased significantly one month later (p=0.028), but was not significantly different from the original baseline (p=0.069).

_Analysts building repeated-measures pipelines can keep up with R statistics techniques via daily.dev._

## Similar posts on daily.dev

- [McNemar’s test in R](https://daily.dev/posts/mcnemar-s-test-in-r-muzqqzd1b) · R-bloggers · 0 upvotes · 0 comments
- [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
- [Understanding the Chi-Square Test Beyond the Formula](https://daily.dev/posts/understanding-the-chi-square-test-beyond-the-formula-bt0o9bqgv) · Towards Data Science · 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
- [When it comes to predicting people’s preferences, it pays to consider “the power of three”](https://daily.dev/posts/when-it-comes-to-predicting-people-s-preferences-it-pays-to-consider-the-power-of-three--vp3etwhsn) · MIT News · 0 upvotes · 0 comments

---

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

[View this post on daily.dev](https://daily.dev/posts/cochran-s-q-test-in-r-or-the-extension-of-mcnemar-s-test-for-more-than-two-groups-usp4hlaey)
