Performs Dunn's test for pairwise multiple comparisons of the ranked data. The mean rank of the different groups is compared. Used for post-hoc test following Kruskal-Wallis test.

dunn_test(data, formula, p.adjust.method = "holm")

Arguments

data

a data.frame containing the variables in the formula.

formula

a formula of the form x ~ group where x is a numeric variable giving the data values and group is a factor with one or multiple levels giving the corresponding groups. For example, formula = TP53 ~ cancer_group.

p.adjust.method

method to adjust p values for multiple comparisons. Used when pairwise comparisons are performed. Allowed values include "holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none". If you don't want to adjust the p value (not recommended), use p.adjust.method = "none".

Value

return a data frame with some of the following columns:

  • .y.: the y (outcome) variable used in the test.

  • group1,group2: the compared groups in the pairwise tests.

  • n1,n2: Sample counts.

  • estimate: mean ranks difference.

  • statistic: Test statistic (z-value) used to compute the p-value.

  • p: p-value.

  • p.adj: the adjusted p-value.

  • method: the statistical test used to compare groups.

  • p.signif, p.adj.signif: the significance level of p-values and adjusted p-values, respectively.

The returned object has an attribute called args, which is a list holding the test arguments.

Details

DunnTest performs the post hoc pairwise multiple comparisons procedure appropriate to follow up a Kruskal-Wallis test, which is a non-parametric analog of the one-way ANOVA. The Wilcoxon rank sum test, itself a non-parametric analog of the unpaired t-test, is possibly intuitive, but inappropriate as a post hoc pairwise test, because (1) it fails to retain the dependent ranking that produced the Kruskal-Wallis test statistic, and (2) it does not incorporate the pooled variance estimate implied by the null hypothesis of the Kruskal-Wallis test.

References

Dunn, O. J. (1964) Multiple comparisons using rank sums Technometrics, 6(3):241-252.

Examples

# Simple test ToothGrowth %>% dunn_test(len ~ dose)
#> Warning: `...` must not be empty for ungrouped data frames. #> Did you want `data = everything()`?
#> # A tibble: 3 x 11 #> .y. group1 group2 n1 n2 estimate statistic p method p.adj #> * <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <chr> <dbl> #> 1 len 0.5 1 20 20 19.6 3.55 3.78e- 4 Dunn … 7.56e- 4 #> 2 len 0.5 2 20 20 35.1 6.36 1.98e-10 Dunn … 5.95e-10 #> 3 len 1 2 20 20 15.5 2.81 4.99e- 3 Dunn … 4.99e- 3 #> # … with 1 more variable: p.adj.signif <chr>
# Grouped data ToothGrowth %>% group_by(supp) %>% dunn_test(len ~ dose)
#> # A tibble: 6 x 12 #> supp .y. group1 group2 n1 n2 estimate statistic p method #> * <fct> <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <chr> #> 1 OJ len 0.5 1 10 10 11.1 2.83 4.59e-3 Dunn … #> 2 OJ len 0.5 2 10 10 16.6 4.22 2.45e-5 Dunn … #> 3 OJ len 1 2 10 10 5.45 1.39 1.66e-1 Dunn … #> 4 VC len 0.5 1 10 10 10.3 2.62 8.87e-3 Dunn … #> 5 VC len 0.5 2 10 10 19.7 5.01 5.57e-7 Dunn … #> 6 VC len 1 2 10 10 9.40 2.39 1.69e-2 Dunn … #> # … with 2 more variables: p.adj <dbl>, p.adj.signif <chr>