# pingouin.cochran

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

Cochran Q test. Special case of the Friedman test when the dependant variable is binary.

Parameters
dvstring

Name of column containing the binary dependant variable.

withinstring

Name of column containing the within-subject factor.

subjectstring

Name of column containing the subject identifier.

datapandas DataFrame

DataFrame

export_filenamestring

Filename (without extension) for the output file. If None, do not export the table. By default, the file will be created in the current python console directory. To change that, specify the filename with full path.

Returns
statsDataFrame

Test summary

'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