How to Perform Dunn’s Test in R

Spread the love

Dunn’s test is a non-parametric post-hoc test used after a Kruskal-Wallis test, which itself is a non-parametric alternative to one-way ANOVA. When the Kruskal-Wallis test indicates a statistically significant difference, Dunn’s test can help pinpoint which groups are different.

In this article, we delve into how to perform Dunn’s test in R, how to interpret the results, and provide a real-world example for context.

Table of Contents

  1. Prerequisites
  2. Data Preparation
  3. Understanding Kruskal-Wallis Test
  4. Performing Dunn’s Test
  5. Interpretation of Results
  6. Case Study
  7. Advantages and Disadvantages
  8. Conclusion

1. Prerequisites

Software Requirements

  • R (version 3.6.0 or later)
  • RStudio (optional, but recommended)

Packages

  • dunn.test

You can install the dunn.test package from CRAN:

install.packages("dunn.test")

Basic Knowledge of Kruskal-Wallis Test

Since Dunn’s test follows the Kruskal-Wallis test, a fundamental understanding of the Kruskal-Wallis test is beneficial.

2. Data Preparation

Input Data

Your data should be well-structured, typically in a data frame. You should have at least two groups to compare.

Import Data into R

To read a .csv file:

data <- read.csv("your_file_path.csv")

3. Understanding Kruskal-Wallis Test

Before performing Dunn’s test, it’s customary to run a Kruskal-Wallis test to detect any overall differences between groups.

kruskal_test_result <- kruskal.test(Score ~ Group, data=data)
print(kruskal_test_result)

4. Performing Dunn’s Test

Load the Package

library(dunn.test)

Execute the Test

After ensuring significance in the Kruskal-Wallis test, execute Dunn’s test:

dunn_result <- dunn.test(data$Score, g=data$Group, method="bonferroni")
print(dunn_result)

5. Interpretation of Results

The output provides pairwise comparisons between groups, Z-values, p-values, and adjusted p-values (when multiple testing corrections are applied).

If the adjusted p-value for a group comparison is below a chosen significance level (e.g., 0.05), there’s evidence to reject the null hypothesis for that specific group comparison, suggesting a significant difference.

6. Case Study

Consider a researcher studying the effects of three different teaching methods on student performance. The scores from three groups of students are:

  • Group A: Traditional method
  • Group B: Online method
  • Group C: Blended method

First, the Kruskal-Wallis test is performed to check for overall differences. If significant differences are found, Dunn’s test can help determine which teaching methods differ significantly in student performance.

library(dunn.test)

# Sample Data
scores <- c(85, 88, 90, 87, 86, 91, 92, 89, 90, 93, 80, 82, 83, 81, 85)
group <- factor(rep(letters[1:3], each=5))

# Kruskal-Wallis Test
kruskal_test_result <- kruskal.test(scores ~ group)
print(kruskal_test_result)

# If significant, perform Dunn's Test
if (kruskal_test_result$p.value < 0.05) {
  dunn_result <- dunn.test(scores, g=group, method="bonferroni")
  print(dunn_result)
}

7. Advantages and Disadvantages

Advantages

  • Non-parametric: Dunn’s test doesn’t assume a normal distribution.
  • Multiple Comparisons: Offers a way to make pairwise group comparisons post Kruskal-Wallis.

Disadvantages

  • Power: Non-parametric tests might have less power compared to their parametric counterparts, meaning they might fail to detect differences when they exist.
  • Overuse: Only to be used after a significant Kruskal-Wallis test.

8. Conclusion

Dunn’s test is a powerful non-parametric tool to make pairwise group comparisons after a significant Kruskal-Wallis test. Its use in R, aided by the dunn.test package, makes it accessible and straightforward for researchers across fields.

When analyzing data, it’s essential to match the statistical test to the type and distribution of your data. Dunn’s test provides an avenue for those instances when data doesn’t meet the assumptions of parametric tests. As always, understanding the underlying principles and assumptions of the test is crucial for its appropriate application.

Posted in RTagged

Leave a Reply