Reputation: 89
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 !!!
Upvotes: 1
Views: 1717
Reputation: 510
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.
Upvotes: 1