MerQuR+Statistics Glossary

Statistics Glossary → Cochran's Q Test

Cochran's Q Testanalysis

A test of whether the success (yes) rates of three or more yes/no conditions measured on the same people are equal; it generalises the McNemar test to more than two conditions.

Concept

When the same people are assessed with a binary outcome under several conditions (e.g. the same patients' response to three drugs, whether the same pupils solve three problems), the observations are not independent. Comparing the conditions with a chi-square test as if they were independent groups would therefore be wrong. Cochran's Q test asks whether the 'yes' rates differ across conditions while accounting for this matched structure, in which each person is compared with themselves.

The test compares the total number of 'yes' answers in each condition with what would be expected if the conditions were equal. People who give the same answer in every condition (all yes or all no) carry no information about differences between conditions; the test draws its information only from people whose answer changes across conditions. The Q statistic approximately follows a chi-square distribution with k − 1 degrees of freedom (k being the number of conditions); with two conditions the test is equivalent to the McNemar test.

A significant Q only says that 'at least two conditions have different rates'; to see which conditions differ, pairs are compared with McNemar tests and the p values are adjusted for multiple comparisons. In small samples the chi-square approximation weakens and an exact or Monte Carlo p should be preferred. The 'yes' rates of the conditions and an effect size should be reported with the result.

When to use it

  • When comparing three or more binary measurements or conditions on the same people (e.g. response to three treatments, presence of a symptom at three time points, selection rates of the options of a multiple-response question).
  • With only two conditions use the McNemar test; if the conditions involve different people, use the chi-square test of independence.
  • If the outcome is ordinal or continuous rather than binary, use the Friedman test or repeated-measures ANOVA; to model the effect of further variables too, use generalised estimating equations (GEE) or mixed-effects logistic regression.

An everyday example

A catering company asks 40 people to taste three recipes of the same soup and say 'I like it / I don't' for each. Twenty-eight like the first recipe, 20 the second and 15 the third. Since the same people tasted all three, the groups are not independent. Cochran's Q test checks whether the approval rates (70%, 50%, 37.5%) really differ between the recipes; if it is significant, pairwise McNemar tests show which recipes differ from one another.

Parameters in MerQur

Binary columns (direct input)

Concept: Columns holding the same people's binary outcome under each condition; each row is one person and each column one condition. The matching comes from this row structure: the values in a row belong to the same person.

Everyday example: In the catering example there are three columns, Recipe 1, Recipe 2 and Recipe 3, where 1 means 'I like it' and 0 'I don't'. Each of the 40 rows is one taster.

What it does: Takes the k binary variables of the same subjects as input; rows with a missing value are deleted listwise, and rows that are all 0 are kept. Two-level text columns (F/U) are converted to 0/1 (the alphabetically second level = 1; a note is written on screen).

Effect on the result: Q, df and p. If Q is undefined (all cases have equal row totals), Q and p are not written, a "no decision" note is given and no post-hoc test is done.

On the validation data: Drugs (F = 1): Q = 8.4706, df 2, p = 0.014476. Lawn (wide matrix): Q = 16.9535, p = 0.0007225. In Kent (1/blank) in direct mode all 12 remaining cases have all 4 devices and Q is undefined (0/0).

MR Set

Concept: If the conditions are stored as the options of a multiple-response question rather than as separate columns, applies the test across those options. The question 'are the options chosen equally often?' is then answered while accounting for the fact that the same people may tick several options.

Everyday example: If the company asked 'which recipes did you like? (you may tick more than one)', the answers are stored as a multiple-response set. Cochran's Q compares the approval rates of the set's three options directly.

What it does: Computes Cochran's Q among the options of a multiple-response set; a blank cell counts as "not selected".

Effect on the result: Cases with no selection are removed (farmer2 storage 279 -> 278, Kent 435 -> 429). Q and p stay the same, η²_Q and the percentages differ from direct mode; a base note is written to the output ("η²_Q base: n = 278").

On the validation data: Q = 117.40 for farmer2 y, Q = 731.66 for Kent. Kent η²_Q = 0.5685; Laptop 92.5% (direct mode: 91.3%).

→ Multiple-response set (MR set)

Long format: subject, condition, binary outcome

Concept: If the data are stored in long format, with one row per person-condition combination (person ID, condition name, outcome), converts them to wide format with one row per person. The result is the same as if the data had been entered in wide format from the start.

Everyday example: The tasting records may be kept as a 120-row list such as 'taster 7, Recipe 2, liked'. The long-format option turns this list into a table of 40 rows × 3 columns automatically.

What it does: Converts data with subject x condition rows into a wide 0/1 matrix; if the outcome is text, the second ordered level counts as 1.

Effect on the result: Data format only; the result equals that of the wide format.

On the validation data: Drugs long (F/U, U = 1) Q = 8.4706; lawn long (Yes = 1) Q = 16.9535, matching the wide format.

Post hoc (None, Pairwise McNemar (exact binomial), Pairwise McNemar χ² (continuity-corrected), Pairwise McNemar χ² (uncorrected)) and p adjustment (Bonferroni, Holm, Benjamini-Hochberg (FDR))

Concept: When Q is significant, tests one by one with McNemar tests which pairs of conditions differ. Since the risk of false alarms grows with the number of pairs, the p values are adjusted with the Bonferroni, Holm or Benjamini-Hochberg method.

Everyday example: With three recipes there are three pairs: 1-2, 1-3 and 2-3. The adjusted p values might show that only the first and third recipes differ, while the second does not clearly differ from either.

What it does: Performs pairwise McNemar tests between pairs of options (discordant pairs b, c) and adjusts the p-values with the selected method. The adjustment is effective only when a post-hoc test is selected.

Effect on the result: Pair p-values and significance decisions.

On the validation data: Drugs A-C (b = 20, c = 8): exact p 0.0357 (Bonferroni 0.1071); Yates χ² 4.3214, p 0.0376; uncorrected χ² 5.1429, p 0.0233 (BH 0.0350). Lawn uncorrected + FDR: Irrigation-MowHeight p 0.00389 (FDR 0.0200).

→ Post hoc tests (pairwise comparisons)

p computation (Asymptotic χ², Monte Carlo (B = 10,000), Exact (permutation))

Concept: Sets how the p value for Q is computed. The asymptotic method uses the chi-square approximation and is reliable with an adequate sample; the exact and Monte Carlo methods compute the p value directly by shuffling each person's answers across conditions within that person, and are preferred in small samples.

Everyday example: Had the company worked with only 8 tasters, the chi-square approximation would be rough. The exact p considers every possible way each taster's three answers could be spread across the recipes and computes how often a result as extreme as the observed one would occur.

What it does: At small n (n < 4k), instead of the asymptotic χ²(k - 1), computes an exact or Monte Carlo p from the within-subject conditional permutation distribution; the asymptotic p is always written as well.

Effect on the result: An additional p row; Q does not change. If the exact distribution is too large, a warning is given and Monte Carlo is used.

On the validation data: Drugs exact p = 0.017501 (asymptotic 0.014476; full enumeration), Monte Carlo 0.0203. Lawn exact 0.000343, Monte Carlo 0.0007. For farmer1 (n = 262, k = 5) full enumeration is too large, so MerQur switches to Monte Carlo.

→ Exact test and exact p-value

Confidence Level (%90, %95, %99, Other (custom))

Concept: No confidence intervals are given in this analysis; the chosen level only sets the threshold (α = 1 − confidence level) for the 'significant' decision of the Q test and the pairwise comparisons. Q and p do not change.

Everyday example: If the company will only switch to a new recipe on strong evidence, it chooses 99% confidence; only differences with p below 0.01 are then taken into account.

What it does: Only the decision threshold alpha = 1 - confidence level (the Q and post-hoc decisions).

Effect on the result: Decision texts and post-hoc marks change; Q and p do not change.

On the validation data: Drugs p = 0.0145: "H₀ rejected" at 90% and 95%, not rejected at 99%; at 80% the A-C and B-C pairs are significant.

→ Confidence level and confidence interval

Example on real data

Data: SAS/STAT PROC FREQ Cochran's Q example (Drugs)

Variables: binary columns Drug_A, Drug_B, Drug_C (the same patients' response to three drugs, 1 = favourable)

  • Question: Are the favourable response rates of three drugs (A, B, C) given to the same 46 patients equal?
  • Assumption: The measurements are dependent (matched) binary data; every patient received all three drugs. Cochran's Q generalizes the McNemar test to more than two conditions.
  • Result: Q(2) = 8.47, p = .014. H0 is rejected: the favourable response rates of at least two drugs differ.
  • Effect size: η²_Q = Q / (n(k-1)) = 0.092; a small to medium effect.
  • Descriptive: The favourable response rate is 60.9% (28/46) for A and B and 34.8% (16/46) for C; the difference appears to come from drug C.
  • Further analysis: Pairwise McNemar tests (with a multiple-comparison adjustment) should be run to see which pairs differ.
  • APA: Cochran's Q(2) = 8.47, p = .014, η²_Q = .09.

Related concepts

Permutation p-valuePost hoc tests (pairwise comparisons)Multiple-response set (MR set)Exact test and exact p-valueFalse discovery rate (FDR, Benjamini-Hochberg, Storey q)Eta squared (η²) and partial eta squared (η²ₚ)Holm (step-down Bonferroni) methodContinuity correction (Yates)

The numbers in the examples are MerQur's output on independent, publicly available validation data; see the MerQur Technical Note for details.