Cochrans Q Test
Cochrans Q Test
Cochrans Q Test
com
Chapter 521
Cochran’s Q Test
Introduction
This procedure computes the non-parametric Cochran’s Q test for related categories where the response is binary.
Cochran’s Q is used for testing k = 2 or more matched sets, where a binary response (e.g. 0 or 1) is recorded from
each category within each subject. Cochran’s Q tests the null hypothesis that the proportion of “successes” is the
same in all groups versus the alternative that the proportion is different in at least one of the groups.
Cochran’s Q test is an extension of the McNemar test to a situation where there are more than two matched
samples. When Cochran’s Q test is computed with only k = 2 groups, the results are equivalent to those obtained
from the McNemar test (without continuity correction). Cochran’s Q is also considered to be a special case of the
non-parametric Friedman test, which is similar to repeated measures ANOVA and is used to detect differences in
multiple matched sets with numeric responses. When the responses are binary, the Friedman test becomes
Cochran’s Q test.
This procedure also computes two-sided, pairwise multiple comparison tests that allow you to determine which of
the individual groups are different if the null hypothesis in Cochran’s Q test is rejected. The individual alpha level
is adjusted using the Bonferroni method to control the overall experiment-wise error rate.
This procedure is based on the results and formulas given in chapter 26 of Sheskin (2011). We refer you there for
additional information about Cochran’s Q test.
Experimental Design
A typical design for this scenario involves N individuals where a binary measurement (e.g. 0 or 1) is made on
each individual for each of k categories, where k ≥ 2. Typical data might appear as
where, in this case, each subject responds to 3 different conditions with either a Yes (1) or No (0). In NCSS, the
responses may be coded as either text values (e.g. Yes, No) or numeric values (e.g. 0, 1).
521-1
© NCSS, LLC. All Rights Reserved.
NCSS Statistical Software NCSS.com
Cochran’s Q Test
Technical Details
Suppose we have k binary measurements on each of 𝑁𝑁 subjects (where the “subject” may be a set of matched
individuals). Let 𝑌𝑌𝑖𝑖,𝑗𝑗 be the binary response from subject i in category j (i = 1 to N, j = 1 to k), with success = 1
and failure = 0. Let the proportions, 𝜋𝜋1 , 𝜋𝜋2 , … , 𝜋𝜋𝑘𝑘 , represent the proportion of “successes” in each of the k
groups.
Cochran’s Q is used to test the null hypothesis
𝐻𝐻0 : 𝜋𝜋1 = 𝜋𝜋2 = … = 𝜋𝜋𝑘𝑘
versus the alternative
𝐻𝐻𝐴𝐴 : 𝜋𝜋a ≠ 𝜋𝜋b for at least one pair 𝜋𝜋a , 𝜋𝜋b, with a ≠ b and 1 ≤ a, b ≤ k.
In NCSS, these proportions, 𝜋𝜋a and 𝜋𝜋b, are displayed as percentages.
Assumptions
The Cochran’s Q test and associated multiple comparisons require the following assumptions:
1. Responses are binary and from k matched samples.
2. The subjects are independent of one another and were selected at random from a larger population.
3. The sample size is sufficiently “large”. (As a rule of thumb, the number of subjects for which the
responses are not all 0’s or 1’s, n, should be ≥ 4 and nk should be ≥ 24. This assumption is not required
for the exact binomial McNemar test.)
𝐶𝐶 = � �� 𝑌𝑌𝑖𝑖,𝑗𝑗 �
𝑗𝑗=1 𝑖𝑖=1
𝑁𝑁 𝑘𝑘
𝑇𝑇 = � �� 𝑌𝑌𝑖𝑖,𝑗𝑗 �
𝑖𝑖=1 𝑗𝑗=1
2
𝑁𝑁 𝑘𝑘
𝑅𝑅 = � �� 𝑌𝑌𝑖𝑖,𝑗𝑗 �
𝑖𝑖=1 𝑗𝑗=1
For “large” samples, the test statistic, Q, is distributed as chi-square with 𝑘𝑘 − 1 degrees of freedom. As in the
McNemar test, only subjects who do not have the same response in all categories contribute to the overall Q
statistic.
521-2
© NCSS, LLC. All Rights Reserved.
NCSS Statistical Software NCSS.com
Cochran’s Q Test
Multiple Comparisons
When the null hypothesis of success proportion equality is rejected by Cochran’s Q test, you can proceed to
determine which of the groups are different by computing multiple pairwise comparisons.
Pairwise tests between groups “a” and “b” test the null hypothesis
𝐻𝐻0 : 𝜋𝜋a = 𝜋𝜋b
versus the alternative
𝐻𝐻𝐴𝐴 : 𝜋𝜋a ≠ 𝜋𝜋b
In NCSS, these proportions, 𝜋𝜋a and 𝜋𝜋b, are displayed as percentages.
NCSS provides two methods as described in chapter 26 of Sheskin (2011). The first method identifies the
minimum required difference, MRD, needed to declare a pair of experimental conditions as significantly different.
The second method simply employs pairwise McNemar tests among groups to find significant differences.
Both multiple comparison methods use the Bonferroni alpha adjustment to control the overall experiment-wise
error of the tests. The adjustment simply divides the overall required alpha, 𝛼𝛼, by the number of pairwise tests, c,
where
𝑘𝑘(𝑘𝑘 − 1)
𝑐𝑐 = .
2
For example, if the desired overall alpha were 0.05 and three groups were being compared, then the individual
alpha level for each test would be 0.05/[3(2)/2] = 0.05/3 = 0.0167.
𝑘𝑘𝑘𝑘 − 𝑅𝑅
𝑀𝑀𝑀𝑀𝑀𝑀 = 𝑧𝑧𝑎𝑎𝑎𝑎𝑎𝑎 �2 � �
𝑁𝑁 2 𝑘𝑘(𝑘𝑘 − 1)
𝑇𝑇 = � �� 𝑌𝑌𝑖𝑖,𝑗𝑗 �
𝑖𝑖=1 𝑗𝑗=1
2
𝑁𝑁 𝑘𝑘
𝑅𝑅 = � �� 𝑌𝑌𝑖𝑖,𝑗𝑗 �
𝑖𝑖=1 𝑗𝑗=1
521-3
© NCSS, LLC. All Rights Reserved.
NCSS Statistical Software NCSS.com
Cochran’s Q Test
and
𝑧𝑧𝑎𝑎𝑎𝑎𝑎𝑎 is the value of the �1 − 𝛼𝛼𝑎𝑎𝑎𝑎𝑎𝑎 /2� quantile from the standard normal distribution.
Two groups are declared to be significantly different with protected overall alpha, 𝛼𝛼, if their absolute difference in
proportions is greater than MRD, that is if
|𝜋𝜋a − 𝜋𝜋b | > 𝑀𝑀𝑀𝑀𝑀𝑀
McNemar Tests
The McNemar test statistic for each pair of groups is computed as
(𝑛𝑛1 − 𝑛𝑛2 )2
𝑀𝑀 =
𝑛𝑛1 + 𝑛𝑛2
where
𝑛𝑛1 = number of subjects where group “a” response = 0 and group “b” response = 1.
𝑛𝑛2 = number of subjects where group “a” response = 1 and group “b” response = 0.
Large-Sample (Asymptotic)
For sufficiently large sample sizes (i.e. n ≥ 4 and nk ≥ 24, where n is the number of subjects for which the
responses are not all 0’s or 1’s), the test statistic, M, is asymptotically distributed as chi-square with 1 degree of
freedom. The p-value for the individual test with protected overall alpha, 𝛼𝛼, is computed as
2
P-Value = Pr �𝑀𝑀 > 𝜒𝜒1−𝛼𝛼 𝑎𝑎𝑎𝑎𝑎𝑎 ,1
�
2
where 𝜒𝜒1−𝛼𝛼 𝑎𝑎𝑎𝑎𝑎𝑎 ,1
is the value of the �1 − 𝛼𝛼𝑎𝑎𝑎𝑎𝑎𝑎 � quantile of the chi-square distribution with 1 degree of freedom.
Exact Test
Exact p-values for the McNemar test can also be computed by enumerating and summing individual binomial
probabilities of results more extreme than the observed. The exact test results are more accurate than the
asymptotic test results because there is no approximation.
Data Structure
The data may be entered in two formats, as shown in the examples below. The examples give the binary responses
of 12 subjects to each of 3 experimental conditions.
The first format, shown in the first table below, puts the responses for each group in separate columns; that is,
each column contains all responses for each condition. Each row corresponds to a single subject. This format
allows for the use of an additional optional frequency variable for summarized data.
The second format, shown in the second table below, arranges the data so that all responses are entered in a single
column. A grouping variable contains an index that gives the group (Condition 1, 2, or 3) to which each row of
data belongs. The subject variable specifies the individual to which each response belongs. This second format
allows you to specify multiple response variables; a separate analysis is carried out for each response variable.
521-4
© NCSS, LLC. All Rights Reserved.
NCSS Statistical Software NCSS.com
Cochran’s Q Test
521-5
© NCSS, LLC. All Rights Reserved.
NCSS Statistical Software NCSS.com
Cochran’s Q Test
Procedure Options
This section describes the options available in this procedure.
Variables Tab
This panel specifies the variables used in the analysis.
Input Type
In this procedure, there are two ways to format the data for analysis. Specify which method you want to use.
Variables
Response Variables (Displayed when Input Type = Multiple Response Variables)
Enter two or more binary response variables. Values may be text or numeric.
You can enter the column names or numbers directly, or double-click in the box to display a Column Selection
window that will let you select the variables from a list.
The dataset must include two or more binary response variables. Each category is represented by a separate
column. All information about a specific subject is entered on a single row. A single analysis is performed for all
of the variables at once.
Example Dataset
R1 R2 R3
0 1 1
1 0 1
1 0 0
521-6
© NCSS, LLC. All Rights Reserved.
NCSS Statistical Software NCSS.com
Cochran’s Q Test
521-7
© NCSS, LLC. All Rights Reserved.
NCSS Statistical Software NCSS.com
Cochran’s Q Test
Example Dataset
Subj Grp Resp
1 A 1
1 B 1
1 C 0
2 A 0
2 B 1
2 C 1
Reports Tab
This tab controls which statistical reports and tables are displayed in the output.
Data Summary
Data Summary Report
Check this option to display a summary of the data used in the analysis with key statistics and helpful
information.
Tests
Cochran’s Q Test
Check this option to output Cochran’s Q Test. This is the primary test for this procedure.
Multiple Comparisons using Minimum Required Absolute Difference
Check this option to output a report with pairwise comparisons between all groups, made using the Minimum
Required Absolute Difference. This multiple comparison procedure uses the Bonferroni alpha-level adjustment so
that the overall experiment-wise alpha level is achieved.
521-8
© NCSS, LLC. All Rights Reserved.
NCSS Statistical Software NCSS.com
Cochran’s Q Test
A Note on Power
This multiple comparison method uses all of the data, not just the values from subjects who have different
responses for the two categories, so some argue that this method is more powerful than using multiple McNemar
tests (see Note #9 on page 1135 of Sheskin (2011)).
Multiple Comparisons using the McNemar Test
Check this option to output a report with pairwise comparisons between all groups, made using the McNemar
Test. The Bonferroni adjustment is applied and the alpha level is adjusted based the number of pairwise
comparisons so that the overall experiment-wise alpha level is achieved.
A Note on Power
This multiple comparison method uses just the values from subjects who have different responses for the two
categories, not all of the data. For this reason some argue that this method is less powerful than using the
Minimum Required Absolute Difference (see Note #9 on page 1135 of Sheskin (2011)).
Report Options
Variable Names
Specify whether to use variable names, variable labels, or both to label output reports. In this discussion, the
variables are the columns of the data table.
• Names
Variable names are the column headings that appear on the data table. They may be modified by clicking the
Column Info button on the Data window or by clicking the right mouse button while the mouse is pointing to
the column heading.
• Labels
This refers to the optional labels that may be specified for each column. Clicking the Column Info button on
the Data window allows you to enter them.
• Both
Both the variable names and labels are displayed.
Comments
1. Most reports are formatted to receive about 12 characters for variable names.
2. Variable Names cannot contain blanks or math symbols (like + - * / . ,), but variable labels can.
521-9
© NCSS, LLC. All Rights Reserved.
NCSS Statistical Software NCSS.com
Cochran’s Q Test
Value Labels
Value Labels are used to make reports more legible by assigning meaningful labels to numbers and codes.
The options are
• Data Values
All data are displayed in their original format, regardless of whether a value label has been set or not.
• Value Labels
All values of variables that have a value label variable designated are converted to their corresponding value
label when they are output. This does not modify their value during computation.
• Both
Both data value and value label are displayed.
Example
A variable named GENDER (used as a grouping variable) contains 1’s and 2’s. By specifying a value label for
GENDER, the report can display “Male” instead of 1 and “Female” instead of 2. This option specifies whether
(and how) to use the value labels.
Table Formatting
Column Justification
Specify whether data columns in the contingency tables will be left or right justified.
Column Widths
Specify how the widths of columns in the contingency tables will be determined.
The options are
• Custom (User-Specified)
Specify the widths (in inches) of the columns directly instead of having the software calculate them for you.
521-10
© NCSS, LLC. All Rights Reserved.
NCSS Statistical Software NCSS.com
Cochran’s Q Test
• Single Value
If you enter a single value, that value will be used as the width for all data columns in the table.
• List of Values
Enter a list of values separated by spaces corresponding to the widths of each column. The first value is used
for the width of the first data column, the second for the width of the second data column, and so forth. Extra
values will be ignored. If you enter fewer values than the number of columns, the last value in your list will
be used for the remaining columns.
Type the word “Autosize” for any column to cause the program to calculate it's width for you. For example,
enter “1 Autosize 0.7” to make column 1 be 1 inch wide, column 2 be sized by the program, and column 3 be
0.7 inches wide.
Wrap Column Headings onto Two Lines
Check this option to make column headings wrap onto two lines. Use this option to condense your table when
your data are spaced too far apart because of long column headings.
Decimal Places
Item Decimal Places
These decimal options allow the user to specify the number of decimal places for items in the output. Your choice
here will not affect calculations; it will only affect the format of the output.
• Auto
If one of the “Auto” options is selected, the ending zero digits are not shown. For example, if “Auto (0 to 7)”
is chosen,
0.0500 is displayed as 0.05
1.314583689 is displayed as 1.314584
The output formatting system is not designed to accommodate “Auto (0 to 13)”, and if chosen, this will likely
lead to lines that run on to a second line. This option is included, however, for the rare case when a very large
number of decimals is needed.
Omit Percent Sign after Percentages
The program normally adds a percent sign, %, after each percentage. Checking this option will cause this percent
sign to be omitted.
521-11
© NCSS, LLC. All Rights Reserved.
NCSS Statistical Software NCSS.com
Cochran’s Q Test
Responses: 2 (0, 1)
Groups (k): 3 (Exam1, Exam2, Exam3)
Subjects or Blocks (N): 12
• Number with responses
that are not all equal (n): 11 (nk = 33)*
The Data Summary report gives a summary description of the data used in the analysis. The summary indicates
that the large-sample conditions (n ≥ 4 and nk ≥ 24) are met. One subject passed every exam, so his/her responses
will not contribute to the Cochran’s Q test statistic.
521-12
© NCSS, LLC. All Rights Reserved.
NCSS Statistical Software NCSS.com
Cochran’s Q Test
Response
Variable
0 1 Total
Exam1 Count 6 6 12
% within Group 50.00 50.00 100.00
Exam2 Count 2 10 12
% within Group 16.67 83.33 100.00
Exam3 Count 9 3 12
% within Group 75.00 25.00 100.00
Total Count 17 19 36
% within Group 47.22 52.78 100.00
This report give the counts and percentages of each response within each category. Exam 2 has the highest pass
rate with 83.33%, while Exam 3 has the lowest pass rate with only 25%.
Chi-Square Asymptotic
Statistic Prob Reject H0
Test Type Q DF Level at α = 0.05?
Cochran's Q 2-Sided 6.7273 2 0.03461 Yes
Cochran’s Q test has a p-value of 0.03461, indicating that the success rate for at least one group is different from
the others. Because this result is significant, we can proceed to consider the multiple comparison tests.
* These tests should only be considered if the null hypothesis of equality was rejected by Cochran's Q Test.
† Individual Comparison Alpha = (Overall Alpha)/c = 0.05/3 = 0.01667.
These multiple comparison results indicate that exams 2 and 3 are significantly different from each other with an
absolute different of 58.33%.
521-13
© NCSS, LLC. All Rights Reserved.
NCSS Statistical Software NCSS.com
Cochran’s Q Test
* These tests should only be considered if the null hypothesis of equality was rejected by Cochran's Q Test.
† Individual Comparison Alpha = (Overall Alpha)/c = 0.05/3 = 0.01667.
These multiple comparison results indicate that there are no pairs significantly different from one another. It’s
interesting to note here that no pairs were found to be different even though the overall Cochran’s Q test found a
significant difference and the multiple comparisons test using minimum required absolute difference found a
difference between exams 2 and 3. This is likely due to the fact that McNemar test has lower overall power
because only discordant pairs are used in the computation of the test statistic. The other multiple comparison
procedure uses all of the data and, thus, has more power.
Plots Section
Plots Section
This section provides a graphical representation of the counts and percentages for each response within each
category.
521-14
© NCSS, LLC. All Rights Reserved.
NCSS Statistical Software NCSS.com
Cochran’s Q Test
Output
Data Summary
Rows Processed: 8
Rows with Missing Values: 0
Rows Used in the Analysis: 8
Responses: 2 (0, 1)
Groups (k): 3 (Exam1, Exam2, Exam3)
Subjects or Blocks (N): 12
• Number with responses
that are not all equal (n): 11 (nk = 33)*
521-15
© NCSS, LLC. All Rights Reserved.
NCSS Statistical Software NCSS.com
Cochran’s Q Test
Cochran's Q Test
(Exam1 by Exam2 by Exam3)
H0: The proportions of [Response = "1"] in all groups are equal.
H1: The proportion of [Response = "1"] in at least one group is different.
Chi-Square Asymptotic
Statistic Prob Reject H0
Test Type Q DF Level at α = 0.05?
Cochran's Q 2-Sided 6.7273 2 0.03461 Yes
The Data Summary report indicates that only 8 rows were processed this time (12 rows were processed in
Example 1), but the number of subjects, 12, is the same as in Example 1 because some of the rows represent more
than one individual. The Cochran’s Q test results are exactly the same as in Example 1.
521-16
© NCSS, LLC. All Rights Reserved.
NCSS Statistical Software NCSS.com
Cochran’s Q Test
Output
Combined Table
B Count 11 9 20
% within Group 55.00 45.00 100.00
C Count 7 13 20
% within Group 35.00 65.00 100.00
D Count 14 6 20
% within Group 70.00 30.00 100.00
Total Count 39 41 80
% within Group 48.75 51.25 100.00
Cochran's Q Test
(A by B by C by D)
H0: The proportions of [Response = "Yes"] in all groups are equal.
H1: The proportion of [Response = "Yes"] in at least one group is different.
Chi-Square Asymptotic
Statistic Prob Reject H0
Test Type Q DF Level at α = 0.05?
Cochran's Q 2-Sided 6.2239 3 0.10121 No
Cochran’s Q test indicates that there is not a significant difference among the 4 medications. There is no reason to
look at the multiple comparison tests at this point.
521-17
© NCSS, LLC. All Rights Reserved.
NCSS Statistical Software NCSS.com
Cochran’s Q Test
521-18
© NCSS, LLC. All Rights Reserved.
NCSS Statistical Software NCSS.com
Cochran’s Q Test
Output
Combined Table
Response
Variable
0 1 Total
Chenesco Count 9 3 12
% within Group 75.00 25.00 100.00
Gemini Count 9 3 12
% within Group 75.00 25.00 100.00
Howasaki Count 3 9 12
% within Group 25.00 75.00 100.00
Total Count 21 15 36
% within Group 58.33 41.67 100.00
Cochran's Q Test
(Chenesco by Gemini by Howasaki)
H0: The proportions of [Response = "1"] in all groups are equal.
H1: The proportion of [Response = "1"] in at least one group is different.
Chi-Square Asymptotic
Statistic Prob Reject H0
Test Type Q DF Level at α = 0.05?
Cochran's Q 2-Sided 8.0000 2 0.01832 Yes
* These tests should only be considered if the null hypothesis of equality was rejected by Cochran's Q Test.
† Individual Comparison Alpha = (Overall Alpha)/c = 0.05/3 = 0.01667.
* These tests should only be considered if the null hypothesis of equality was rejected by Cochran's Q Test.
† Individual Comparison Alpha = (Overall Alpha)/c = 0.05/3 = 0.01667.
The results from NCSS match Sheskin (2011), with slight differences due to rounding. Key matched items are
highlighted in purple.
521-19
© NCSS, LLC. All Rights Reserved.