1

I am trying to obtain the significance letters with the function multcompLetters2( ) after performing a Pairwise Dunn Rank Sum Test with function dunnTest( ). However, after assigning the output of the test to an object (dunn.iris), I am unable to call it correctly in multcompLetters2( ). I am trying to refer only to the adjusted p values (P.adj) of the object, but I always get the following error message " Error in strsplit(x, sep) : non-character argument ".

I used "iris" dataset to make my problem reproducible.

# Packages
install.packages("ggpubr")
install.packages("tidyverse")
install.packages("rcompanion")
install.packages("multcompView")
install.packages("dunn.test")
install.packages("FSA")

library(rcompanion)
library(multcompView)
library(tidyverse)
library(ggpubr)
library(dunn.test)
library(FSA)

# Loading data
data("iris")

# Dunn's Test 
dunn.iris <- dunnTest(iris$Sepal.Length, iris$Species, method = "bonferroni")

# Obtaining significance letters
cld <- multcompLetters2(Sepal.Length ~ Species, dunn.iris$Species[, "P.adj"], as.data.frame(iris))

Thank you !!!

r2evans
  • 141,215
  • 6
  • 77
  • 149

1 Answers1

1

I wouldn't use the agricolae package for a post-test for Kruskal-Wallis. The documentation says it uses Fisher LSD. I didn't look in to how this is implemented. But it doesn't sound like an appropriate post-hoc test for KW.

Dunn test (1964) is a common and appropriate post-hoc test.

I've always found multcompLetters a little tricky to work with. Because of this, I wrote a function rcompanion::cldList() to make things a little easier.

The following just uses the P.adj and Comparison from the dunnTest() output.

Note that you may need to specify $res from the dunnTest() output.

Also, the multcompLetters() function was having problems with extra spaces in Comparison, so I used gsub() to remove them.

Diff = dunn.iris$res$P.adj < 0.05
Names = gsub(" ", "", dunn.iris$res$Comparison)
names(Diff) = Names
CLD = multcompLetters(Diff)
CLD

It may be slightly easier to rcompanion::cldList().

library(rcompanion)
CLD = cldList(P.adj ~ Comparison, data=dunn.iris$res)
CLD

Note that either of these just uses the Comparison and P.adj information, so they don't know the order of the treatments. If you have several treatments, it's a good idea to order the treatments by median or mean rank so that the resultant cld letter come out in a logical order.

Sal Mangiafico
  • 440
  • 3
  • 8
  • It looks like it works perfectly fine ! However, I don't exactly know how to order the treatments so that the cld letter is associated to the appropriate group. I tried with dplyr by ordering the groups by mean rank before performing your code, but the outputs of KW, dunn.test() and of CLD are still in the same order. – chiliconcarno Aug 23 '23 at 15:43
  • To be clear, I know I could put CLD in the right order afterwards, but I would prefer to obtain each letter already associated with the proper group. Also, I tried the code you provided in this question using dplyr, but for me I think it doesn't influence the order that dunnTest( ) is processing the groups, since the order I obtain is still the same : https://stackoverflow.com/questions/62694809/writing-a-function-to-summarize-the-results-of-dunn-testdunn-test – chiliconcarno Aug 23 '23 at 16:37
  • I believe with *dunnTest()* it used to be the case that you could order the factor variable, and it would preserve that order. Now it looks like it forces it to alphabetical order. A simple hack would just be to rename the factors, e.g. *c("aHighest", "bMedium", "cLowest")*. It's hacky, but it would be easy to then change the names back. I'm not sure about functions. Like, *PMCMRplus::kwAllPairsDunnTest*. – Sal Mangiafico Aug 24 '23 at 18:33
  • Ok Yes, it seems like a working method. Finally, I did something similar by adding a new column with a number for each group (1 = highest mean group, 2 = 2nd highest mean group, etc.) and by using this variable instead of Species in dunnTest(), the letters were then attributed to the right group. – chiliconcarno Aug 25 '23 at 19:11