## Cochran's Q Test

Cochran's Q test is appropriate for random-blocks or repeated-measures data where the values are dichotomous
(represented by zero or any non-zero numbers). The test computes a statistic Q which is compared
to a critical value from the Chi-squared distribution. The Chi-squared distribution is an asymptotic approximation for the exact
null distribution of Q. The null hypothesis (H_{0}) is that the proportion of non-zero members is the same for all columns.

Consider the following data contained in wave1:

Group1 | Group2 | Group3 | Group4 | Group5 | |

Block1 | 0 | 0 | 0 | 0 | 1 |

Block2 | 0 | 0 | 0 | 0 | 1 |

Block3 | 0 | 0 | 0 | 1 | 1 |

Block4 | 0 | 1 | 0 | 1 | 1 |

Block5 | 0 | 1 | 0 | 1 | 0 |

Block6 | 1 | 1 | 0 | 1 | 0 |

Block7 | 1 | 1 | 0 | 0 | 0 |

Block8 | 1 | 0 | 0 | 0 | 0 |

Block9 | 1 | 0 | 0 | 0 | 0 |

The test statistic is smaller than the critical value

In this case there are 5 columns and 9 rows with a total of 45 entries which implies that the Chi-square approximation can be used (greater than 4 columns and 24 total entires). To run the test execute the following command:

StatsCochranTest/T=1/Q wave1

The results are given in the Cochran Test table:

Rows | Columns | Statistic | Critical | Conclusion | P-value |

9 | 5 | 5.56522 | 9.48773 | 1 | 0.234056 |

It may be somewhat perplexing that despite the fact that Group3 column is identically zero, the test does not suggest rejection of the null hypothesis where the proportion of "ON" blocks is the same across all groups.

Keeping Group3 column fixed, you can increase the proportion of "ON" blocks in all other columns until the Q value exceeds the critical value. This is done in wave2 shown below.

Group1 | Group2 | Group3 | Group4 | Group5 | |

Block1 | 0 | 0 | 0 | 0 | 1 |

Block2 | 0 | 0 | 0 | 0 | 1 |

Block3 | 0 | 0 | 0 | 1 | 1 |

Block4 | 0 | 1 | 0 | 1 | 1 |

Block5 | 1 | 1 | 0 | 1 | 1 |

Block6 | 1 | 1 | 0 | 1 | 1 |

Block7 | 1 | 1 | 0 | 1 | 0 |

Block8 | 1 | 1 | 0 | 0 | 0 |

Block9 | 1 | 0 | 0 | 0 | 0 |

To run the test on these data execute the following command:

StatsCochranTest/T=1/Q wave2

The results are given in the Cochran Test table:

Rows | Columns | Statistic | Critical | Conclusion | P-value |

9 | 5 | 10.3636 | 9.48773 | 0 | 0.0347281 |

As expected the test statistic has increased above the critical value and so the H_{0} must be rejected, i.e.,
the proportion of non-zero entries in the different columns is not the same.