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
 data
pandas.DataFrame
DataFrame
 dvstring
Name of column containing the binary dependent variable.
 withinstring
Name of column containing the withinsubject factor.
 subjectstring
Name of column containing the subject identifier.
 data
 Returns
 stats
pandas.DataFrame
'Q'
: The Cochran Q statistic'punc'
: Uncorrected pvalue'dof'
: degrees of freedom
 stats
Notes
The Cochran Q test [1] 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.705882 0.034981