How to use multcompletters() to generate compact letters for p values?

57 views Asked by At

I used a one-way repeated measures ANOVA to analyze survey data, where participants (N=31) reported CertaintyRating in five different Scenarios.

I'm looking for ways to add letters to my boxplot. I looked up that you can use multcompletters4() to generate the letters connoting sig differences between pairs, but it's not working for me. Maybe because it's built for TukeysHSD() outputs only? What should I use instead?

Here's what my data looks like:

A tibble: 155 × 5

Codename D2 Scenario CertaintyRating scenario_num

1 DC_10 4 Q1.3_13 95 1
2 DC_10 4 Q2.3_13 90 2
3 DC_10 4 Q3.3_13 80 3
4 DC_10 4 Q4.3_13 60 4
5 DC_10 4 Q5.3_13 90 5
6 DC_11 4 Q1.3_13 90 1
7 DC_11 4 Q2.3_13 90 2
8 DC_11 4 Q3.3_13 75 3
9 DC_11 4 Q4.3_13 92 4
10 DC_11 4 Q5.3_13 92 5

ℹ 145 more rows

Boxplot of CertaintyRating by scenario_num

Here's my code:

#repeated measures ANOVA 

model_ranova_N31 <- aov(CertaintyRating~factor(scenario_num)+Error(factor(Codename)),
                    data=data)
summary(model_ranova_N31)

#post-hoc

bonferroni_N31 <-
  data %>%
    pairwise_t_test(CertaintyRating~scenario_num, 
    paired = TRUE,
    p.adjust.method = "bonferroni")

#compact letter display

multcompLetters4(model_ranova_N31,bonferroni_N31)

Doing the above gave me the below error:

Error in x[, "p adj"]: ! Can't subset columns that don't exist. ✖ Column p adj doesn't exist.

The column name with p values is "p.adj", so I tried renaming and removing the period:

bonferroni_N31 <- rename(bonferroni_N31, c('p.adj' = 'p adj'))

But when I ran again, I got this error:
multcompLetters4(model_ranova_N31,bonferroni_N31)
Error in `comp[[i]]`:

! Can't extract columns past the end.

ℹ Location 2 doesn't exist.

ℹ There is only 1 column.

Would appreciate any help!

0

There are 0 answers