Friedman test in R, or the nonparametric version of the repeated measures ANOVA

Wait 5 sec.

[This article was first published on R on Stats and R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.IntroductionDataFriedman testAim and hypothesesAssumptionsIn RWith base RWith the {rstatix} packageInterpretationsPost-hoc testsPairwise Wilcoxon signed-rank testsNemenyi testConover testCombination of statistical results and plotSummaryReferencesIntroductionIn a previous article, we showed how to perform a repeated measures ANOVA in R to compare a quantitative variable measured on the same subjects under three or more related conditions, or at three or more points in time.As for many statistical tests, its results can only be trusted if some assumptions are met, in particular the normality of the residuals (at least for small samples) and the sphericity of the data. When they are not, or when the dependent variable is only ordinal, its nonparametric version can be used: the Friedman test, proposed by the economist Milton Friedman in 1937 in a paper whose title sums up its purpose: “The use of ranks to avoid the assumption of normality implicit in the analysis of variance” (Friedman 1937).The article about the Kruskal-Wallis test, the nonparametric version of the one-way ANOVA, already pointed in this direction: if the observations between samples are dependent (for instance, the same individuals measured before, during and after a treatment), the Friedman test should be preferred to take this dependency into account. The present article picks up that thread.These four tests, all used to compare three groups or more, form two pairs of parametric and nonparametric tests:Independent samplesRelated samplesParametricOne-way ANOVARepeated measures ANOVANonparametricKruskal-Wallis testFriedman testIn other words, the Friedman test is the “related-samples” counterpart of the Kruskal-Wallis test. Both work on ranks instead of raw values, but the Kruskal-Wallis test ranks all observations together, whereas the Friedman test ranks the measurements within each subject, which is how it takes the dependency between the samples into account.In the rest of the article, we show how to perform and interpret the Friedman test in R, how to follow it up with post-hoc tests, and how to present all the results on a single plot.DataWe use the same scenario as in the repeated measures ANOVA article: a treatment against chronic pain, with pain measured from 0 (no pain at all) to 100 (unbearable pain) on the same patients (i) before, (ii) during and (iii) one month after the treatment. This time, however, the data come from a small pilot study with 16 patients, and some scores are affected by flare-ups:# number of patientsn