# Cochran's Q test - overview

This page offers structured overviews of one or more selected methods. Add additional methods for comparisons by clicking on the dropdown button in the right-hand column. To practice with a specific method click the button at the bottom row of the table

Cochran's Q test
One sample $z$ test for the mean
McNemar's test
Logistic regression
Independent/grouping variableIndependent variableIndependent variableIndependent variables
One within subject factor ($\geq 2$ related groups)None2 paired groupsOne or more quantitative of interval or ratio level and/or one or more categorical with independent groups, transformed into code variables
Dependent variableDependent variableDependent variableDependent variable
One categorical with 2 independent groupsOne quantitative of interval or ratio levelOne categorical with 2 independent groupsOne categorical with 2 independent groups
Null hypothesisNull hypothesisNull hypothesisNull hypothesis
H0: $\pi_1 = \pi_2 = \ldots = \pi_I$

Here $\pi_1$ is the population proportion of 'successes' for group 1, $\pi_2$ is the population proportion of 'successes' for group 2, and $\pi_I$ is the population proportion of 'successes' for group $I.$
H0: $\mu = \mu_0$

Here $\mu$ is the population mean, and $\mu_0$ is the population mean according to the null hypothesis.

Let's say that the scores on the dependent variable are scored 0 and 1. Then for each pair of scores, the data allow four options:

1. First score of pair is 0, second score of pair is 0
2. First score of pair is 0, second score of pair is 1 (switched)
3. First score of pair is 1, second score of pair is 0 (switched)
4. First score of pair is 1, second score of pair is 1
The null hypothesis H0 is that for each pair of scores, P(first score of pair is 0 while second score of pair is 1) = P(first score of pair is 1 while second score of pair is 0). That is, the probability that a pair of scores switches from 0 to 1 is the same as the probability that a pair of scores switches from 1 to 0.

Other formulations of the null hypothesis are:

• H0: $\pi_1 = \pi_2$, where $\pi_1$ is the population proportion of ones for the first paired group and $\pi_2$ is the population proportion of ones for the second paired group
• H0: for each pair of scores, P(first score of pair is 1) = P(second score of pair is 1)

Model chi-squared test for the complete regression model:
• H0: $\beta_1 = \beta_2 = \ldots = \beta_K = 0$
Wald test for individual regression coefficient $\beta_k$:
• H0: $\beta_k = 0$
or in terms of odds ratio:
• H0: $e^{\beta_k} = 1$
Likelihood ratio chi-squared test for individual regression coefficient $\beta_k$:
• H0: $\beta_k = 0$
or in terms of odds ratio:
• H0: $e^{\beta_k} = 1$
in the regression equation $\ln \big(\frac{\pi_{y = 1}}{1 - \pi_{y = 1}} \big) = \beta_0 + \beta_1 \times x_1 + \beta_2 \times x_2 + \ldots + \beta_K \times x_K$. Here $x_i$ represents independent variable $i$, $\beta_i$ is the regression weight for independent variable $x_i$, and $\pi_{y = 1}$ represents the true probability that the dependent variable $y = 1$ (or equivalently, the proportion of $y = 1$ in the population) given the scores on the independent variables.
Alternative hypothesisAlternative hypothesisAlternative hypothesisAlternative hypothesis
H1: not all population proportions are equalH1 two sided: $\mu \neq \mu_0$
H1 right sided: $\mu > \mu_0$
H1 left sided: $\mu < \mu_0$

The alternative hypothesis H1 is that for each pair of scores, P(first score of pair is 0 while second score of pair is 1) $\neq$ P(first score of pair is 1 while second score of pair is 0). That is, the probability that a pair of scores switches from 0 to 1 is not the same as the probability that a pair of scores switches from 1 to 0.

Other formulations of the alternative hypothesis are:

• H1: $\pi_1 \neq \pi_2$
• H1: for each pair of scores, P(first score of pair is 1) $\neq$ P(second score of pair is 1)

Model chi-squared test for the complete regression model:
• H1: not all population regression coefficients are 0
Wald test for individual regression coefficient $\beta_k$:
• H1: $\beta_k \neq 0$
or in terms of odds ratio:
• H1: $e^{\beta_k} \neq 1$
If defined as Wald $= \dfrac{b_k}{SE_{b_k}}$ (see 'Test statistic'), also one sided alternatives can be tested:
• H1 right sided: $\beta_k > 0$
• H1 left sided: $\beta_k < 0$
Likelihood ratio chi-squared test for individual regression coefficient $\beta_k$:
• H1: $\beta_k \neq 0$
or in terms of odds ratio:
• H1: $e^{\beta_k} \neq 1$
AssumptionsAssumptionsAssumptionsAssumptions
• Sample of 'blocks' (usually the subjects) is a simple random sample from the population. That is, blocks are independent of one another
• Scores are normally distributed in the population
• Population standard deviation $\sigma$ is known
• Sample is a simple random sample from the population. That is, observations are independent of one another
• Sample of pairs is a simple random sample from the population of pairs. That is, pairs are independent of one another
• In the population, the relationship between the independent variables and the log odds $\ln (\frac{\pi_{y=1}}{1 - \pi_{y=1}})$ is linear
• The residuals are independent of one another
Often ignored additional assumption:
• Variables are measured without error
Also pay attention to:
• Multicollinearity
• Outliers
Test statisticTest statisticTest statisticTest statistic
If a failure is scored as 0 and a success is scored as 1:

$Q = k(k - 1) \dfrac{\sum_{groups} \Big (\mbox{group total} - \frac{\mbox{grand total}}{k} \Big)^2}{\sum_{blocks} \mbox{block total} \times (k - \mbox{block total})}$

Here $k$ is the number of related groups (usually the number of repeated measurements), a group total is the sum of the scores in a group, a block total is the sum of the scores in a block (usually a subject), and the grand total is the sum of all the scores.

Before computing $Q$, first exclude blocks with equal scores in all $k$ groups.
$z = \dfrac{\bar{y} - \mu_0}{\sigma / \sqrt{N}}$
Here $\bar{y}$ is the sample mean, $\mu_0$ is the population mean according to the null hypothesis, $\sigma$ is the population standard deviation, and $N$ is the sample size.

The denominator $\sigma / \sqrt{N}$ is the standard deviation of the sampling distribution of $\bar{y}$. The $z$ value indicates how many of these standard deviations $\bar{y}$ is removed from $\mu_0$.
$X^2 = \dfrac{(b - c)^2}{b + c}$
Here $b$ is the number of pairs in the sample for which the first score is 0 while the second score is 1, and $c$ is the number of pairs in the sample for which the first score is 1 while the second score is 0.
Model chi-squared test for the complete regression model:
• $X^2 = D_{null} - D_K = \mbox{null deviance} - \mbox{model deviance}$
$D_{null}$, the null deviance, is conceptually similar to the total variance of the dependent variable in OLS regression analysis. $D_K$, the model deviance, is conceptually similar to the residual variance in OLS regression analysis.
Wald test for individual $\beta_k$:
The wald statistic can be defined in two ways:
• Wald $= \dfrac{b_k^2}{SE^2_{b_k}}$
• Wald $= \dfrac{b_k}{SE_{b_k}}$
SPSS uses the first definition.

Likelihood ratio chi-squared test for individual $\beta_k$:
• $X^2 = D_{K-1} - D_K$
$D_{K-1}$ is the model deviance, where independent variable $k$ is excluded from the model. $D_{K}$ is the model deviance, where independent variable $k$ is included in the model.
Sampling distribution of $Q$ if H0 were trueSampling distribution of $z$ if H0 were trueSampling distribution of $X^2$ if H0 were trueSampling distribution of $X^2$ and of the Wald statistic if H0 were true
If the number of blocks (usually the number of subjects) is large, approximately the chi-squared distribution with $k - 1$ degrees of freedomStandard normal distribution

If $b + c$ is large enough (say, > 20), approximately the chi-squared distribution with 1 degree of freedom.

If $b + c$ is small, the Binomial($n$, $P$) distribution should be used, with $n = b + c$ and $P = 0.5$. In that case the test statistic becomes equal to $b$.

Sampling distribution of $X^2$, as computed in the model chi-squared test for the complete model:
• chi-squared distribution with $K$ (number of independent variables) degrees of freedom
Sampling distribution of the Wald statistic:
• If defined as Wald $= \dfrac{b_k^2}{SE^2_{b_k}}$: approximately the chi-squared distribution with 1 degree of freedom
• If defined as Wald $= \dfrac{b_k}{SE_{b_k}}$: approximately the standard normal distribution
Sampling distribution of $X^2$, as computed in the likelihood ratio chi-squared test for individual $\beta_k$:
• chi-squared distribution with 1 degree of freedom
Significant?Significant?Significant?Significant?
If the number of blocks is large, the table with critical $X^2$ values can be used. If we denote $X^2 = Q$:
• Check if $X^2$ observed in sample is equal to or larger than critical value $X^{2*}$ or
• Find $p$ value corresponding to observed $X^2$ and check if it is equal to or smaller than $\alpha$
Two sided:
Right sided:
Left sided:
For test statistic $X^2$:
• Check if $X^2$ observed in sample is equal to or larger than critical value $X^{2*}$ or
• Find $p$ value corresponding to observed $X^2$ and check if it is equal to or smaller than $\alpha$
If $b + c$ is small, the table for the binomial distribution should be used, with as test statistic $b$:
• Check if $b$ observed in sample is in the rejection region or
• Find two sided $p$ value corresponding to observed $b$ and check if it is equal to or smaller than $\alpha$
For the model chi-squared test for the complete regression model and likelihood ratio chi-squared test for individual $\beta_k$:
• Check if $X^2$ observed in sample is equal to or larger than critical value $X^{2*}$ or
• Find $p$ value corresponding to observed $X^2$ and check if it is equal to or smaller than $\alpha$
For the Wald test:
• If defined as Wald $= \dfrac{b_k^2}{SE^2_{b_k}}$: same procedure as for the chi-squared tests. Wald can be interpret as $X^2$
• If defined as Wald $= \dfrac{b_k}{SE_{b_k}}$: same procedure as for any $z$ test. Wald can be interpreted as $z$.
n.a.$C\%$ confidence interval for $\mu$n.a.Wald-type approximate $C\%$ confidence interval for $\beta_k$
-$\bar{y} \pm z^* \times \dfrac{\sigma}{\sqrt{N}}$
where the critical value $z^*$ is the value under the normal curve with the area $C / 100$ between $-z^*$ and $z^*$ (e.g. $z^*$ = 1.96 for a 95% confidence interval).

The confidence interval for $\mu$ can also be used as significance test.
-$b_k \pm z^* \times SE_{b_k}$
where the critical value $z^*$ is the value under the normal curve with the area $C / 100$ between $-z^*$ and $z^*$ (e.g. $z^*$ = 1.96 for a 95% confidence interval).
n.a.Effect sizen.a.Goodness of fit measure $R^2_L$
-Cohen's $d$:
Standardized difference between the sample mean and $\mu_0$: $$d = \frac{\bar{y} - \mu_0}{\sigma}$$ Cohen's $d$ indicates how many standard deviations $\sigma$ the sample mean $\bar{y}$ is removed from $\mu_0.$
-$R^2_L = \dfrac{D_{null} - D_K}{D_{null}}$
There are several other goodness of fit measures in logistic regression. In logistic regression, there is no single agreed upon measure of goodness of fit.
n.a.Visual representationn.a.n.a.
---
Equivalent ton.a.Equivalent ton.a.
Friedman test, with a categorical dependent variable consisting of two independent groups.-
-
Example contextExample contextExample contextExample context
Subjects perform three different tasks, which they can either perform correctly or incorrectly. Is there a difference in task performance between the three different tasks?Is the average mental health score of office workers different from $\mu_0 = 50$? Assume that the standard deviation of the mental health scores in the population is $\sigma = 3.$Does a tv documentary about spiders change whether people are afraid (yes/no) of spiders?Can body mass index, stress level, and gender predict whether people get diagnosed with diabetes?
SPSSn.a.SPSSSPSS
Analyze > Nonparametric Tests > Legacy Dialogs > K Related Samples...
• Put the $k$ variables containing the scores for the $k$ related groups in the white box below Test Variables
• Under Test Type, select Cochran's Q test
-Analyze > Nonparametric Tests > Legacy Dialogs > 2 Related Samples...
• Put the two paired variables in the boxes below Variable 1 and Variable 2
• Under Test Type, select the McNemar test
Analyze > Regression > Binary Logistic...
• Put your dependent variable in the box below Dependent and your independent (predictor) variables in the box below Covariate(s)
Jamovin.a.JamoviJamovi
Jamovi does not have a specific option for the Cochran's Q test. However, you can do the Friedman test instead. The $p$ value resulting from this Friedman test is equivalent to the $p$ value that would have resulted from the Cochran's Q test. Go to:

ANOVA > Repeated Measures ANOVA - Friedman
• Put the $k$ variables containing the scores for the $k$ related groups in the box below Measures
-Frequencies > Paired Samples - McNemar test
• Put one of the two paired variables in the box below Rows and the other paired variable in the box below Columns
Regression > 2 Outcomes - Binomial
• Put your dependent variable in the box below Dependent Variable and your independent variables of interval/ratio level in the box below Covariates
• If you also have code (dummy) variables as independent variables, you can put these in the box below Covariates as well
• Instead of transforming your categorical independent variable(s) into code variables, you can also put the untransformed categorical independent variables in the box below Factors. Jamovi will then make the code variables for you 'behind the scenes'
Practice questionsPractice questionsPractice questionsPractice questions