I get an error when I try to run the Dunntest on my data and I can't figure out what's causing it.
I have 4 groups with ordinal discrete data, the Kruskal-Wallis test suggest a significant difference between groups but I can't run the dunntest afterwards.
Any help is appreciated.
> mast_cells
# A tibble: 20 × 2
group score
<ord> <dbl>
1 1 1
2 1 1
3 1 1
4 1 1
5 1 1
6 2 3
7 2 4
8 2 2
9 2 1
10 2 3
11 3 2
12 3 1
13 3 2
14 3 3
15 3 3
16 4 3
17 4 2
18 4 3
19 4 2
20 4 2
> mast_cells$group <- ordered(mast_cells$group ,
+ levels = c("1", "2", "3", "4"))
> kruskal.test( score ~ group, data = mast_cells)
Kruskal-Wallis rank sum test
data: score by group
Kruskal-Wallis chi-squared = 9.1875, df = 3, p-value = 0.0269
> library(FSA)
> dunnTest(score ~ group,
+ data = mast_cells,
+ method="Benjamini-Yekuteili")
Error in if (tmp$Eclass != "factor") { : the condition has length > 1
>
dunTest
function does not accept formula as an argument, you need specify your data vector as the first argument, and factor as the second one. Additionally if you choose Benjamini-Yekuteili adjustement method for multiple comparison, option method = "by"
should be specified.
See the code below:
library(FSA)
mast_cells <- structure(
list(group = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L,
2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L),
levels = c("1", "2", "3", "4"), class = c("ordered", "factor")),
score = c(1L, 1L, 1L, 1L, 1L, 3L, 4L, 2L, 1L, 3L,
2L, 1L, 2L, 3L, 3L, 3L, 2L, 3L, 2L, 2L)),
row.names = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
"11", "12", "13", "14", "15", "16", "17", "18", "19", "20"),
class = "data.frame")
dunnTest(mast_cells$score, mast_cells$group, method = "by")
Output:
Dunn (1964) Kruskal-Wallis multiple comparison
p-values adjusted with the Benjamini-Yekuteili method.
Comparison Z P.unadj P.adj
1 1 - 2 -2.6685305 0.007618387 0.11199029
2 1 - 3 -2.1348244 0.032775359 0.16059926
3 2 - 3 0.5337061 0.593544894 1.00000000
4 1 - 4 -2.4999917 0.012419622 0.09128422
5 2 - 4 0.1685388 0.866159449 1.00000000
6 3 - 4 -0.3651673 0.714986507 1.00000000