Post-hoc multiple comparisons using Tukey test and Dunn's test
Perform Tukey test for multiple comparisons:
# 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))
library(multcomp)
tukey <- glht(kruskal.test(value ~ group, data=data), linfct=mcp(group="Tukey"))
summary(tukey)
Perform Dunn’s test for multiple comparisons
library(dunn.test)
dunn <- dunn.test(data$value, data$group, method="holm")
print(dunn$comparison)
print(dunn$adjusted)
The output of the summary(tukey)
function should look something like this:
Tukey Contrasts
Fit: kruskal.test(formula = value ~ group, data = data)
$group
diff lwr upr p adj
Group 2-Group 1 10.00 -15.694 35.694 0.77042
Group 3-Group 1 -7.00 -32.694 18.694 0.89234
Group 3-Group 2 -17.00 -42.694 8.694 0.13131
The Tukey Contrasts output shows the pairwise differences between groups, along with the lower and upper bounds of the 95% confidence interval for each difference, and the adjusted p-value
for each comparison.
In this case, the adjusted p-values
are all greater than 0.05, suggesting that none of the pairwise differences are statistically significant.
The output of the print(dunn$comparison)
function should look something like this:
Comparison of x by group
(Holm)
Levels Group 1 Group 2
Group 2 0.50989 -
Group 3 0.99999 0.06478
The print(dunn$comparison)
output shows the pairwise comparisons between groups, along with the Holm-adjusted p-value
for each comparison.
In this case, we can see that the pairwise comparison between Group 1 and Group 3 has an adjusted p-value
of 0.99999, which suggests that there is no significant difference in medians between these two groups. However, the pairwise comparison between Group 2 and Group 3 has an adjusted p-value
of 0.06478, which suggests that there is some evidence of a significant difference in medians between these two groups.