# pingouin.cochran

pingouin.cochran(data=None, dv=None, within=None, subject=None)[source]

Cochran Q test. A special case of the Friedman test when the dependent variable is binary.

Parameters
datapandas.DataFrame

DataFrame

dvstring

Name of column containing the binary dependent variable.

withinstring

Name of column containing the within-subject factor.

subjectstring

Name of column containing the subject identifier.

Returns
statspandas.DataFrame
• 'Q': The Cochran Q statistic

• 'p-unc': Uncorrected p-value

• 'dof': degrees of freedom

Notes

The Cochran Q test  is a non-parametric test for ANOVA with repeated measures where the dependent variable is binary.

Data are expected to be in long-format. NaN are automatically removed from the data.

The Q statistics is defined as:

$Q = \frac{(r-1)(r\sum_j^rx_j^2-N^2)}{rN-\sum_i^nx_i^2}$

where $$N$$ is the total sum of all observations, $$j=1,...,r$$ where $$r$$ is the number of repeated measures, $$i=1,...,n$$ where $$n$$ is the number of observations per condition.

The p-value is then approximated using a chi-square distribution with $$r-1$$ degrees of freedom:

$Q \sim \chi^2(r-1)$

References

1

Cochran, W.G., 1950. The comparison of percentages in matched samples. Biometrika 37, 256–266. https://doi.org/10.1093/biomet/37.3-4.256

Examples

Compute the Cochran Q test for repeated measurements.

>>> from pingouin import cochran, read_dataset