Kruskal-Wallis test
The Kruskal-Wallis test is a rank-based non-parametric alternative to the one-way ANOVA and an extension of the Wilcoxon-Mann-Whitney test to allow the comparison of more than two independent groups. It’s usually recommended when the assumptions of one-way ANOVA test are not met (non-normal distributions) or with small samples.
# Example data
group1 <- c(10, 20, 30, 40, 50)
group2 <- c(15, 25, 35, 45, 55)
group3 <- c(5, 10, 15, 20, 25)
data <- data.frame(value=c(group1, group2, group3),
group=rep(c("Group 1", "Group 2", "Group 3"), each=5))
# Perform Kruskal-Wallis test
kruskal.test(value ~ group, data=data)
The output of the kruskal.test() function should look something like this:
Kruskal-Wallis rank sum test
data: value by group
Kruskal-Wallis chi-squared = 7.8, df = 2, p-value = 0.02
The Kruskal-Wallis chi-squared value is the test statistic, and the p-value is the probability of observing such a test statistic under the null hypothesis that the medians of all groups are equal. In this case, we have a small p-value of 0.02, which suggests that we reject the null hypothesis and conclude that there is significant evidence that the medians of at least two groups are different.
Therefore, we can further perform post-hoc multiple comparisons using Tukey test or Dunn’s test to find out which specific groups differ significantly in medians.