pingouin.cochran

pingouin.
cochran
(data=None, dv=None, within=None, subject=None, export_filename=None)[source] Cochran Q test. Special case of the Friedman test when the dependant variable is binary.
 Parameters
 datapandas DataFrame
DataFrame
 dvstring
Name of column containing the binary dependant variable.
 withinstring
Name of column containing the withinsubject factor.
 subjectstring
Name of column containing the subject identifier.
 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 'punc' : Uncorrected pvalue 'dof' : degrees of freedom
Notes
The Cochran Q Test is a nonparametric test for ANOVA with repeated measures where the dependent variable is binary.
Data are expected to be in longformat. NaN are automatically removed from the data.
The Q statistics is defined as:
\[Q = \frac{(r1)(r\sum_j^rx_j^2N^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 pvalue is then approximated using a chisquare distribution with \(r1\) degrees of freedom:
\[Q \sim \chi^2(r1)\]References
 1
Cochran, W.G., 1950. The comparison of percentages in matched samples. Biometrika 37, 256–266. https://doi.org/10.1093/biomet/37.34.256
Examples
Compute the Cochran Q test for repeated measurements.
>>> from pingouin import cochran, read_dataset >>> df = read_dataset('cochran') >>> cochran(data=df, dv='Energetic', within='Time', subject='Subject') Source dof Q punc cochran Time 2 6.706 0.034981