EZ Statistics

Dunn's Test

Calculator

Learn More

Dunn's Test

Definition

Dunn's Test is a non-parametric post-hoc test used after a significant Kruskal-Wallis test to identify which specific groups differ from each other. It compares the difference in the sum of ranks between two groups with the expected average difference. This test is often used when the assumptions of ANOVA are violated, such as normality or homogeneity of variances.

Test Statistics

For comparing groups ii and jj:

zij=RˉiRˉjN(N+1)12(1ni+1nj)z_{ij} = \frac{\bar{R}_i - \bar{R}_j}{\sqrt{\frac{N(N+1)}{12}(\frac{1}{n_i} + \frac{1}{n_j})}}

Where:

  • Rˉi,Rˉj\bar{R}_i, \bar{R}_j = mean ranks for groups ii and jj
  • ni,njn_i, n_j = sample sizes for groups ii and jj
  • NN = total sample size

Key Features

Non-parametric: No assumption of normality
Multiple Comparisons: Accounts for family-wise error rate
Unequal Sample Sizes: Can handle different group sizes

Practical Example

Step 1: State the Data

Test scores for three different teaching methods:

Method AMethod BMethod C
23, 25, 21, 22, 2018, 19, 17, 20, 2115, 14, 16, 18, 19
Step 2: Rank All Data

Combined ranking of all values (lowest to highest):

ValueRankGroup
141C
152C
163C
174B
185.5B,C
197.5B,C
209.5A,B
2111.5A,B
2213A
2314A
2515A
Step 3: Calculate Mean Ranks
  • Method A: RˉA=12.6\bar{R}_A = 12.6
  • Method B: RˉB=7.6\bar{R}_B = 7.6
  • Method C: RˉC=4.3\bar{R}_C = 4.3
Step 4: Calculate Test Statistics

For each pair (using the formula):

  • A vs B: zAB=12.67.615×(15+1)12(15+15)=1.774z_{AB} = \frac{12.6-7.6}{\sqrt{\frac{15\times(15+1)}{12}(\frac{1}{5} + \frac{1}{5})}} = 1.774
  • A vs C:zAC=12.64.315×(15+1)12(15+15)=3.122z_{AC} = \frac{12.6-4.3}{\sqrt{\frac{15\times(15+1)}{12}(\frac{1}{5} + \frac{1}{5})}} = 3.122
  • B vs C:zBC=7.64.315×(15+1)12(15+15)=1.348z_{BC} = \frac{7.6-4.3}{\sqrt{\frac{15\times(15+1)}{12}(\frac{1}{5} + \frac{1}{5})}} = 1.348
Step 5: Apply Bonferroni Correction

For 3 groups, we have 3 comparisons:

  • Adjusted α=0.05/3=0.0167\alpha = 0.05/3 = 0.0167
  • Critical value z=±2.39z = \pm2.39
Step 6: Draw Conclusions
  • A vs B: Significant (1.77<2.391.77 \lt 2.39)
  • A vs C: Significant (3.12>2.393.12 \gt 2.39)
  • B vs C: Not significant (1.34<2.391.34 \lt 2.39)

Method A scores significantly differ from C. However, there is no evidence to suggest a significant difference between the scores of Method A and Method B or Method B and Method C.

Code Examples

R
1library(tidyverse)
2library(FSA)
3
4# Data preparation
5data_long <- tibble(
6  Method = rep(c("Method A", "Method B", "Method C"), each = 5),
7  Value = c(23, 25, 21, 22, 20, 18, 19, 17, 20, 21, 15, 14, 16, 18, 19)
8)
9
10# Perform Kruskal-Wallis test
11kruskal_test <- kruskal.test(Value ~ Method, data = data_long)
12print(kruskal_test)
13
14# Perform Dunn's test with Bonferroni correction
15dunn_test <- dunnTest(Value ~ Method, data = data_long, method = "bonferroni")
16print(dunn_test)
Python
1import scikit_posthocs as sp
2import pandas as pd
3import numpy as np
4
5# Example data
6group1 = [23, 25, 21, 22, 20]
7group2 = [18, 19, 17, 20, 21]
8group3 = [15, 14, 16, 18, 19]
9
10# Create a DataFrame
11data = pd.DataFrame({
12    'values': group1 + group2 + group3,
13    'groups': ['A']*5 + ['B']*5 + ['C']*5
14})
15
16# Perform Dunn's test
17dunn = sp.posthoc_dunn(data, val_col='values', group_col='groups', p_adjust='bonferroni')
18print(dunn)

Alternative Tests

Consider these alternatives:

  • Tukey's HSD: When data is normally distributed
  • Games-Howell: When variances are unequal
  • Nemenyi Test: Another non-parametric alternative

Related Calculators

Kruskal-Wallis Test Calculator

Mann-Whitney U Test Calculator

Friedman Test Calculator

One-Way ANOVA Calculator

Help us improve

Found an error or have a suggestion? Let us know!