Analyses Kruskal-Wallis Test
Minimal Working Example
Let’s use the kruskal.test() function to test whether the medians of an
unnamed variable of three unconnected populations (a, b and c) with 10
individuals each are truly different:
set.seed(42)
a <- rnorm(n = 10, mean = 15, sd = 3)
b <- rnorm(n = 10, mean = 10, sd = 3)
c <- rnorm(n = 10, mean = 5, sd = 3)
groups <- as.factor(rep(c("a", "b", "c"), each = 10))
kruskal.test(x = c(a, b, c), g = groups)
##
## Kruskal-Wallis rank sum test
##
## data: c(a, b, c) and groups
## Kruskal-Wallis chi-squared = 19, df = 2, p-value =
## 7e-05
Aarhus University Biostatistics - Why? What? How? 8 / 15