U1 - Kruskal-Wallis Test
by DocP, 08 Jun 2020
If the assumptions of the ANOVA are not met, we might choose to perform a Kruskal-Wallis test.
kruskal.test(WeightLoss ~ Diet)
##
## Kruskal-Wallis rank sum test
##
## data: WeightLoss by Diet
## Kruskal-Wallis chi-squared = 15.902, df = 3, p-value = 0.001188
Note: Some versions of R seem to require that the group variable be an integer rather than a character for the kruskal.test command. I added a third column (NumDiet) to the spreadsheet which replaced the character variable “Diet” with an integer value.
kruskal.test(WeightLoss ~ NumDiet)
##
## Kruskal-Wallis rank sum test
##
## data: WeightLoss by NumDiet
## Kruskal-Wallis chi-squared = 15.902, df = 3, p-value = 0.001188
Previous versions of R could handle the character variable, so this feature may return in the future (it works with the version currently on my computer). Until then, if you have a grouping variable that is coded as character, a numeric replacement may be required.
Note that, in this case, the outcome is very similar to that of the ANOVA.
Unfortunately, there is no equivalent to the Tukey HSD for the K-W test so post hoc comparisons have to be done with a Mann-Whitney test.