0

I asked a question here but and now facing another issue

After running cldList() from the package rcompanion, it gave me a table showing the compact letter display per groups, however, some groups do not show any letters despite being not significantly different with other groups.

The data is too big so i am uploading it here

Is this a bug or am I doing something wrong.

The code I am using is this one

library(FSA)
library(multcompView)
library(rcompanion)
library(ggplot2)
library(ggpubr)
library(tidyr)

raw_df <- read.csv("raw_data.csv")


#After performing Kruskal-Wallis H test, I found significant groups and performed the post hoc test using dunnTest() using the code below

bells <- dunnTest(Group ~ as.factor(Color_Score), method = "bh", data = raw_df)

#I save the P values into a separate variable
piano <- bells$`res`

#After the Dunn Test, I tried to get the compact letter displays.

flute <- cldList(P.adj ~ Comparison, data = piano, threshold = 0.05) 

#This is where the problem starts, overall, I have 40 groups to compare but would only return letters for 38 groups

#I tried plotting the boxplot and adding the compact letter using the code below

ggboxplot(raw_df, x = "Group", y = "Color_Score", 
          combine = FALSE, 
          x.text.angle = 360,
          orientation = "vertical",
          ylab = "Measurement (cm)",
          xlab = "Group", 
          color = "Group",
          fill = "Group", 
          notch = FALSE,
          ggtheme = theme_gray()) + 
            font("xy.text", size = 7, color = "black") + 
            theme(legend.position = "None", 
             axis.text.x =element_text(color = "black")) +  
            color of the y-axis (Measurement) tick labels
            geom_text(data  = flute, 
                      aes(x = Group, y = 12, angle = 90,
                      label = Letter),
                      position = position_nudge(x = 0.1),
                      hjust = 0,
                      color = "red")

Has anybody experience this? I tried to search but could not find any answer to this.

  • Could you please add all necessary packages as library() statements above? Especially make sure we can access the piano object or rather the original dataset. Actually, the very best option would be if you could create the pasted code via the {reprex} package: https://reprex.tidyverse.org/ – Paul Schmidt Oct 08 '21 at 11:41
  • @PaulSchmidt I hope you can look again in the edited version, Sorry I cannot use `repres`, I'll try to study how to use it. But I hope you can look into my problem or provide an alternative solution. Thanks – Tyler Ruddenfort Oct 08 '21 at 14:40

2 Answers2

3

I am author of the cldList() function. Because the function is designed to handle the varied output from different functions, by default it removes characters like spaces, zeros, and equal signs, so that the results can be passed to multcompView::multcompLetters. By removing zeros, in this case, it conflates C1 with C10. The following solves this problem:

flute <-
  cldList(P.adj ~ Comparison,
          data = bells$res,
          threshold = 0.05,
          remove.zero = FALSE)
flute
Sal Mangiafico
  • 440
  • 3
  • 8
1

edit:

Ok, so I used the {copypasta} package to include the data in the code for easier reproducibility (via {reprex}).

data

raw_df  <- tibble::tribble(
  ~Group, ~DAY, ~REPLICATE, ~Color_Score,
    "S1",   7L,         1L,            4,
    "S1",   7L,         2L,          1.7,
    "S1",   7L,         3L,          1.5,
    "S1",   7L,         4L,            2,
    "S2",   7L,         1L,          1.2,
    "S2",   7L,         2L,          1.6,
    "S2",   7L,         3L,          1.8,
    "S2",   7L,         4L,          2.3,
    "S3",   7L,         1L,          1.6,
    "S3",   7L,         2L,          1.6,
    "S3",   7L,         3L,            2,
    "S3",   7L,         4L,          0.9,
    "S4",   7L,         1L,          1.2,
    "S4",   7L,         2L,            2,
    "S4",   7L,         3L,          1.2,
    "S4",   7L,         4L,            2,
    "S5",   7L,         1L,          1.7,
    "S5",   7L,         2L,          1.2,
    "S5",   7L,         3L,          1.5,
    "S5",   7L,         4L,          1.3,
    "S6",   7L,         1L,          1.6,
    "S6",   7L,         2L,          0.8,
    "S6",   7L,         3L,            0,
    "S6",   7L,         4L,            0,
    "S7",   7L,         1L,          1.9,
    "S7",   7L,         2L,            2,
    "S7",   7L,         3L,          2.4,
    "S7",   7L,         4L,          2.6,
    "S8",   7L,         1L,          2.9,
    "S8",   7L,         2L,            3,
    "S8",   7L,         3L,          2.4,
    "S8",   7L,         4L,            2,
    "S9",   7L,         1L,          1.1,
    "S9",   7L,         2L,          1.2,
    "S9",   7L,         3L,          1.2,
    "S9",   7L,         4L,          1.8,
   "S10",   7L,         1L,          2.8,
   "S10",   7L,         2L,          1.7,
   "S10",   7L,         3L,          2.3,
   "S10",   7L,         4L,          2.6,
   "S11",   7L,         1L,          1.5,
   "S11",   7L,         2L,          2.4,
   "S11",   7L,         3L,          1.6,
   "S11",   7L,         4L,          1.3,
    "I1",   7L,         1L,          2.6,
    "I1",   7L,         2L,          2.2,
    "I1",   7L,         3L,          2.8,
    "I1",   7L,         4L,          2.6,
    "I2",   7L,         1L,          2.3,
    "I2",   7L,         2L,          2.4,
    "I2",   7L,         3L,          2.4,
    "I2",   7L,         4L,            2,
    "I3",   7L,         1L,          4.3,
    "I3",   7L,         2L,          1.8,
    "I3",   7L,         3L,          1.8,
    "I3",   7L,         4L,          2.9,
    "I4",   7L,         1L,          2.8,
    "I4",   7L,         2L,          2.7,
    "I4",   7L,         3L,          1.6,
    "I4",   7L,         4L,          1.8,
    "I5",   7L,         1L,          2.5,
    "I5",   7L,         2L,          2.4,
    "I5",   7L,         3L,          1.9,
    "I5",   7L,         4L,          2.7,
    "I6",   7L,         1L,          2.6,
    "I6",   7L,         2L,          2.5,
    "I6",   7L,         3L,          3.1,
    "I6",   7L,         4L,          2.2,
    "I7",   7L,         1L,          2.5,
    "I7",   7L,         2L,          1.7,
    "I7",   7L,         3L,          1.8,
    "I7",   7L,         4L,          2.5,
    "I8",   7L,         1L,            2,
    "I8",   7L,         2L,          2.4,
    "I8",   7L,         3L,            1,
    "I8",   7L,         4L,          1.6,
    "I9",   7L,         1L,          2.2,
    "I9",   7L,         2L,          1.4,
    "I9",   7L,         3L,          2.3,
    "I9",   7L,         4L,          1.8,
   "I10",   7L,         1L,          1.8,
   "I10",   7L,         2L,          2.6,
   "I10",   7L,         3L,          2.1,
   "I10",   7L,         4L,          2.7,
    "C1",   7L,         1L,          1.5,
    "C1",   7L,         2L,          2.3,
    "C1",   7L,         3L,          2.2,
    "C1",   7L,         4L,            3,
    "C2",   7L,         1L,          1.5,
    "C2",   7L,         2L,          1.6,
    "C2",   7L,         3L,          2.8,
    "C2",   7L,         4L,          1.2,
    "C3",   7L,         1L,          2.4,
    "C3",   7L,         2L,          2.2,
    "C3",   7L,         3L,          2.1,
    "C3",   7L,         4L,          3.4,
    "C4",   7L,         1L,          2.5,
    "C4",   7L,         2L,          2.7,
    "C4",   7L,         3L,          1.8,
    "C4",   7L,         4L,          3.6,
    "C5",   7L,         1L,          0.9,
    "C5",   7L,         2L,          2.1,
    "C5",   7L,         3L,          1.2,
    "C5",   7L,         4L,          2.1,
    "C6",   7L,         1L,          2.6,
    "C6",   7L,         2L,          1.8,
    "C6",   7L,         3L,          1.9,
    "C6",   7L,         4L,          2.5,
    "C7",   7L,         1L,          1.7,
    "C7",   7L,         2L,          0.4,
    "C7",   7L,         3L,          1.8,
    "C7",   7L,         4L,            1,
    "C8",   7L,         1L,          0.4,
    "C8",   7L,         2L,            1,
    "C8",   7L,         3L,          0.4,
    "C8",   7L,         4L,          1.4,
    "C9",   7L,         1L,          0.9,
    "C9",   7L,         2L,          1.1,
    "C9",   7L,         3L,          0.8,
    "C9",   7L,         4L,          1.6,
   "C10",   7L,         1L,          2.1,
   "C10",   7L,         2L,          1.5,
   "C10",   7L,         3L,          1.9,
   "C10",   7L,         4L,          1.7,
    "T1",   7L,         1L,          0.8,
    "T1",   7L,         2L,          1.2,
    "T1",   7L,         3L,          1.5,
    "T1",   7L,         4L,          1.3,
    "T2",   7L,         1L,          1.9,
    "T2",   7L,         2L,          2.4,
    "T2",   7L,         3L,          2.2,
    "T2",   7L,         4L,            2,
    "T3",   7L,         1L,          1.9,
    "T3",   7L,         2L,          1.8,
    "T3",   7L,         3L,            2,
    "T3",   7L,         4L,          1.8,
    "T4",   7L,         1L,          1.5,
    "T4",   7L,         2L,          1.3,
    "T4",   7L,         3L,          1.9,
    "T4",   7L,         4L,          1.7,
    "T5",   7L,         1L,          2.9,
    "T5",   7L,         2L,          1.8,
    "T5",   7L,         3L,          1.8,
    "T5",   7L,         4L,          2.3,
    "T6",   7L,         1L,          1.8,
    "T6",   7L,         2L,          2.1,
    "T6",   7L,         3L,          2.9,
    "T6",   7L,         4L,          2.3,
    "T7",   7L,         1L,          0.3,
    "T7",   7L,         2L,          0.2,
    "T7",   7L,         3L,            0,
    "T7",   7L,         4L,          0.5,
    "T8",   7L,         1L,          2.6,
    "T8",   7L,         2L,          4.6,
    "T8",   7L,         3L,          1.4,
    "T8",   7L,         4L,          1.7,
    "IR",   7L,         1L,          2.4,
    "IR",   7L,         2L,          1.6,
    "IR",   7L,         3L,          1.6,
    "IR",   7L,         4L,          2.4,
  "CTRL",   7L,         1L,            0,
  "CTRL",   7L,         2L,            0,
  "CTRL",   7L,         3L,            0,
  "CTRL",   7L,         4L,            0,
    "S1",   7L,         1L,          1.5,
    "S1",   7L,         2L,          1.5,
    "S1",   7L,         3L,          1.6,
    "S1",   7L,         4L,          0.9,
    "S2",   7L,         1L,          1.2,
    "S2",   7L,         2L,          1.6,
    "S2",   7L,         3L,          1.4,
    "S2",   7L,         4L,          2.9,
    "S3",   7L,         1L,          1.9,
    "S3",   7L,         2L,          1.3,
    "S3",   7L,         3L,            2,
    "S3",   7L,         4L,          2.5,
    "S4",   7L,         1L,          1.8,
    "S4",   7L,         2L,          0.4,
    "S4",   7L,         3L,            2,
    "S4",   7L,         4L,          2.4,
    "S5",   7L,         1L,          0.8,
    "S5",   7L,         2L,          2.2,
    "S5",   7L,         3L,          1.5,
    "S5",   7L,         4L,          0.5,
    "S6",   7L,         1L,          1.5,
    "S6",   7L,         2L,          1.8,
    "S6",   7L,         3L,          1.7,
    "S6",   7L,         4L,          1.4,
    "S7",   7L,         1L,            2,
    "S7",   7L,         2L,          1.4,
    "S7",   7L,         3L,          2.1,
    "S7",   7L,         4L,          1.2,
    "S8",   7L,         1L,          2.4,
    "S8",   7L,         2L,          1.7,
    "S8",   7L,         3L,          1.4,
    "S8",   7L,         4L,          1.7,
    "S9",   7L,         1L,            3,
    "S9",   7L,         2L,          2.7,
    "S9",   7L,         3L,          3.6,
    "S9",   7L,         4L,          2.8,
   "S10",   7L,         1L,          1.9,
   "S10",   7L,         2L,          1.2,
   "S10",   7L,         3L,          1.2,
   "S10",   7L,         4L,          2.3,
   "S11",   7L,         1L,          1.9,
   "S11",   7L,         2L,          1.5,
   "S11",   7L,         3L,            2,
   "S11",   7L,         4L,          1.7,
    "I1",   7L,         1L,          1.9,
    "I1",   7L,         2L,          1.7,
    "I1",   7L,         3L,          3.5,
    "I1",   7L,         4L,          1.8,
    "I2",   7L,         1L,          0.6,
    "I2",   7L,         2L,          0.8,
    "I2",   7L,         3L,          2.7,
    "I2",   7L,         4L,          1.4,
    "I3",   7L,         1L,          2.7,
    "I3",   7L,         2L,          1.4,
    "I3",   7L,         3L,          2.3,
    "I3",   7L,         4L,          2.4,
    "I4",   7L,         1L,          1.9,
    "I4",   7L,         2L,          2.3,
    "I4",   7L,         3L,          2.7,
    "I4",   7L,         4L,          2.2,
    "I5",   7L,         1L,          1.3,
    "I5",   7L,         2L,          1.7,
    "I5",   7L,         3L,            2,
    "I5",   7L,         4L,          1.5,
    "I6",   7L,         1L,          2.5,
    "I6",   7L,         2L,          2.1,
    "I6",   7L,         3L,          1.3,
    "I6",   7L,         4L,          2.7,
    "I7",   7L,         1L,            0,
    "I7",   7L,         2L,          1.8,
    "I7",   7L,         3L,          2.6,
    "I7",   7L,         4L,          1.8,
    "I8",   7L,         1L,          1.9,
    "I8",   7L,         2L,          3.2,
    "I8",   7L,         3L,          2.5,
    "I8",   7L,         4L,          2.7,
    "I9",   7L,         1L,          2.2,
    "I9",   7L,         2L,          2.7,
    "I9",   7L,         3L,          1.9,
    "I9",   7L,         4L,          2.3,
   "I10",   7L,         1L,          1.9,
   "I10",   7L,         2L,          2.5,
   "I10",   7L,         3L,          1.8,
   "I10",   7L,         4L,          2.8,
    "C1",   7L,         1L,          1.5,
    "C1",   7L,         2L,          2.5,
    "C1",   7L,         3L,          1.5,
    "C1",   7L,         4L,          2.4,
    "C2",   7L,         1L,          2.5,
    "C2",   7L,         2L,          1.7,
    "C2",   7L,         3L,          1.2,
    "C2",   7L,         4L,          2.6,
    "C3",   7L,         1L,          1.9,
    "C3",   7L,         2L,          2.7,
    "C3",   7L,         3L,          2.2,
    "C3",   7L,         4L,          1.5,
    "C4",   7L,         1L,          2.7,
    "C4",   7L,         2L,          1.8,
    "C4",   7L,         3L,          1.9,
    "C4",   7L,         4L,          2.6,
    "C5",   7L,         1L,          2.4,
    "C5",   7L,         2L,          1.1,
    "C5",   7L,         3L,          1.6,
    "C5",   7L,         4L,          0.9,
    "C6",   7L,         1L,          2.9,
    "C6",   7L,         2L,          1.7,
    "C6",   7L,         3L,          3.5,
    "C6",   7L,         4L,          1.9,
    "C7",   7L,         1L,            2,
    "C7",   7L,         2L,          1.5,
    "C7",   7L,         3L,          1.4,
    "C7",   7L,         4L,          1.1,
    "C8",   7L,         1L,          2.1,
    "C8",   7L,         2L,          2.2,
    "C8",   7L,         3L,          2.9,
    "C8",   7L,         4L,          1.5,
    "C9",   7L,         1L,          1.5,
    "C9",   7L,         2L,          1.8,
    "C9",   7L,         3L,          2.1,
    "C9",   7L,         4L,          1.4,
   "C10",   7L,         1L,          2.1,
   "C10",   7L,         2L,          1.5,
   "C10",   7L,         3L,          2.3,
   "C10",   7L,         4L,          1.9,
    "T1",   7L,         1L,          3.2,
    "T1",   7L,         2L,            2,
    "T1",   7L,         3L,          1.6,
    "T1",   7L,         4L,          4.2,
    "T2",   7L,         1L,          1.8,
    "T2",   7L,         2L,          2.7,
    "T2",   7L,         3L,          0.8,
    "T2",   7L,         4L,          1.5,
    "T3",   7L,         1L,            0,
    "T3",   7L,         2L,          2.2,
    "T3",   7L,         3L,          2.7,
    "T3",   7L,         4L,          0.5,
    "T4",   7L,         1L,          1.5,
    "T4",   7L,         2L,          2.3,
    "T4",   7L,         3L,            2,
    "T4",   7L,         4L,          0.7,
    "T5",   7L,         1L,          2.5,
    "T5",   7L,         2L,          2.3,
    "T5",   7L,         3L,          1.7,
    "T5",   7L,         4L,          1.3,
    "T6",   7L,         1L,          0.9,
    "T6",   7L,         2L,          1.4,
    "T6",   7L,         3L,          1.2,
    "T6",   7L,         4L,          0.9,
    "T7",   7L,         1L,          1.6,
    "T7",   7L,         2L,          1.3,
    "T7",   7L,         3L,          2.6,
    "T7",   7L,         4L,          3.1,
    "T8",   7L,         1L,          3.7,
    "T8",   7L,         2L,          1.1,
    "T8",   7L,         3L,            2,
    "T8",   7L,         4L,          2.7,
    "IR",   7L,         1L,          2.9,
    "IR",   7L,         2L,          1.6,
    "IR",   7L,         3L,          2.2,
    "IR",   7L,         4L,          2.4,
  "CTRL",   7L,         1L,            0,
  "CTRL",   7L,         2L,            0,
  "CTRL",   7L,         3L,            0,
  "CTRL",   7L,         4L,            0
  )

code

library(FSA)
library(multcompView)
library(rcompanion)
library(ggplot2)
library(ggpubr)
library(tidyr)

library(tidyverse)
library(emmeans)
library(multcomp)
library(multcompView)

raw_df <- raw_df %>%
  mutate(Group = as.factor(Group))

n_distinct(raw_df$Group)
#> [1] 41

There are 41 distinct groups in the Group column of the raw_df.

bells <-
  FSA::dunnTest(Color_Score ~ Group,
                method = "bh",
                data = raw_df)

bells$res$Comparison %>% 
  str_split(string = ., pattern = " - ") %>%
  unlist() %>% 
  n_distinct()
#> [1] 41

There are still 41 distinct groups appearing in the Comparison column (either left or right of the -) of bells$res after dunnTest().

flute <-
  cldList(P.adj ~ Comparison,
          data = bells$res,
          threshold = 0.05) 

n_distinct(flute$Group)
#> [1] 38

Suddenly, after cldList() there are only 38 distinct groups left. All groups with a 10 in the name are missing. Because of this, I suspected it would have something to do with the function somehow putting e.g. S1 and S10 in the same group. However, I gave the groups completely different names and this still happenend. I am confused and simply do not know how to fix this. This has nothing to do with the boxplot itself so the name of this thread is misleading. You could contact the author of the cldList() function about this with this reproducible code.

alternative code

For debugging I tried an alternative approach and this worked, but also gave very different p-values.

mod <- lm(Color_Score ~ Group, raw_df)
new_bells <- emmeans(mod, specs = "Group")
new_flute <- cld(
  object = new_bells,
  Letters = letters,
  adjust = "bonferroni",
  alpha = 0.05
)

ggboxplot(
  data = raw_df,
  x = "Group",
  y = "Color_Score",
  combine = FALSE,
  x.text.angle = 360,
  orientation = "vertical",
  ylab = "Measurement (cm)",
  xlab = "Group",
  # color = "Group",
  fill = "Group",
  notch = FALSE,
  ggtheme = theme_bw()
) +
  font("xy.text", size = 7, color = "black") +
  theme(legend.position = "None",
        axis.text.x = element_text(
          color = "black",
          angle = 90,
          vjust = 0.5)) +
  geom_text(
    data = new_flute,
    aes(
      x = Group,
      y = 5,
      label = str_trim(.group),
      color = .group
    ),
    angle = 90,
    hjust = 1,
  )

Created on 2021-10-14 by the reprex package (v2.0.1)

Paul Schmidt
  • 1,072
  • 10
  • 23
  • 1
    apologies for the mistake. it should be `bells <- FSA::dunnTest(Color_Score ~ as.factor(Group), method = "bh", data = raw_df)` you are correct, I somehow mixed them up, but still, some groups are not showing the CLD. – Tyler Ruddenfort Oct 13 '21 at 16:33
  • Thanks, I was now able to get further debugging this, but as you can see in my edit - I couldn't solve it. – Paul Schmidt Oct 14 '21 at 08:21
  • Thank you very much for all the help, I guess the only thing to now is to message the author of the cldList() function. Just wanted to ask, have you tried it using your function? – Tyler Ruddenfort Oct 14 '21 at 15:48
  • 1
    What do you mean by that? Did you see my edit in the main answer? In the "alternative code" section I used "my functions" and it worked - it gave letters for all groups. – Paul Schmidt Oct 15 '21 at 09:29
  • 1
    Oh yeah. apologies for that. I didn't notice. thanks for all the help – Tyler Ruddenfort Oct 16 '21 at 04:35