pingouin.friedman

pingouin.friedman(data=None, dv=None, within=None, subject=None, method='chisq')[source]

Friedman test for repeated measurements.

Parameters
datapandas.DataFrame

DataFrame

dvstring

Name of column containing the dependent variable.

withinstring

Name of column containing the within-subject factor.

subjectstring

Name of column containing the subject identifier.

methodstring

Statistical test to perform. Must be 'chisq' (chi-square test) or 'f' (F test). See notes below for explanation.

Returns
statspandas.DataFrame
  • 'W': Kendall’s coefficient of concordance, corrected for ties

If method='chisq'

  • 'Q': The Friedman chi-square statistic, corrected for ties

  • 'dof': degrees of freedom

  • 'p-unc': Uncorrected p-value of the chi squared test

If method='f'

  • 'F': The Friedman F statistic, corrected for ties

  • 'dof1': degrees of freedom of the numerator

  • 'dof2': degrees of freedom of the denominator

  • 'p-unc': Uncorrected p-value of the F test

Notes

The Friedman test is used for one-way repeated measures ANOVA by ranks.

Data are expected to be in long-format.

Note that if the dataset contains one or more other within subject factors, an automatic collapsing to the mean is applied on the dependent variable (same behavior as the ezANOVA R package). As such, results can differ from those of JASP. If you can, always double-check the results.

NaN values are automatically removed.

The Friedman test is equivalent to the test of significance of Kendalls’s coefficient of concordance (Kendall’s W). Most commonly a Q statistic, which has asymptotical chi-squared distribution, is computed and used for testing. However, in [1] they showed the chi-squared test to be overly conservative for small numbers of samples and repeated measures. Instead they recommend the F test, which has the correct size and behaves like a permutation test, but is computationaly much easier.

References

1

Marozzi, M. (2014). Testing for concordance between several criteria. Journal of Statistical Computation and Simulation, 84(9), 1843–1850. https://doi.org/10.1080/00949655.2013.766189

Examples

Compute the Friedman test for repeated measurements.

>>> from pingouin import friedman, read_dataset
>>> df = read_dataset('rm_anova')
>>> friedman(data=df, dv='DesireToKill', within='Disgustingness',
...          subject='Subject')
                  Source         W  ddof1         Q     p-unc
Friedman  Disgustingness  0.099224      1  9.227848  0.002384

This time we will use the F test method.

>>> from pingouin import friedman, read_dataset
>>> df = read_dataset('rm_anova')
>>> friedman(data=df, dv='DesireToKill', within='Disgustingness',
...          subject='Subject', method='f')
                  Source         W     ddof1      ddof2         F     p-unc
Friedman  Disgustingness  0.099224  0.978495  90.021505  10.13418  0.002138

We can see, compared to the previous example, that the p-value is slightly lower. This is expected, since the F test is more powerful (see Notes).