1

So I have installed the multcomp and multcompview packages to RStudio; However, when I go to use the cld function I keep getting this error

Error in UseMethod("cld") : 
no applicable method for 'cld' applied to an object of class "data.frame"

My data is as follows:

Group1 <- c(12.4,10.7,11.9,11.0,12.4,12.3,13.0,12.5,11.2,11.1)
Group2 <- c(8.1,11.5,11.3,8.7,12.7,10.7,9.6,11.3,11.1,13.7)
Group3 <- c(8.5,11.6,10.2,10.9,9.0,9.6,9.9,11.3,10.5,14.2)
Group4 <- c(8.7,9.3,8.2,8.3,9.0,9.4,9.2,12.2,8.5,12.9)
Group5 <- c(12.7,13.2,11.8,11.9,12.2,11.2,13.7,11.8,11.5,9.7)

Combined_Groups<-data.frame(cbind(Group1,Group2,Group3,Group4,Group5))
Combined_Groups #shows spreadsheet like results
summary(Combined_Groups) #min, median, mean, max

Stacked_Groups <- stack(Combined_Groups)
Stacked_Groups #shows the table Stacked_Groups

Anova_Results<-aov(values~ind,data=Stacked_Groups)
summary(Anova_Results) #shows Anova_Results

qf (.95, df1=4, df2=45) #this gives you the critical mean of the F 
distribution

t(apply(Combined_Groups, 2, function(x) c(mean=mean(x), sd=sd(x), 
n=length(x)))) #table of mean,SD,n

tk <-TukeyHSD(Anova_Results)
tk

cld(Combined_Groups, sort = TRUE, by = NULL, Letters = 
"ABCDEFGHIJKLMNOPQRSTUVWXYZ",alpha = 0.05)

What should the correct format of cld be? I want the results from to go from lowest to highest means and then the pairwise comparisons below it in letters.

N.J
  • 21
  • 2
  • 7
  • 1
    (this isn't an answer to question, but use `data.frame(group1, etc..)` instead of `data.frame(cbind(`). – Axeman Oct 30 '17 at 12:21
  • Thank you for the advice. Do you mind explaining why that is better? I am new to R and that was the example I saw online that I have been following. – N.J Oct 31 '17 at 19:43
  • You'd run into issues if some of the variables were not numeric, as `cbind` makes a matrix and therefore coerces all variables to a common type. – Axeman Oct 31 '17 at 21:28
  • So then `cbind` is good for numeric data, but when you have nominal variables it is better to not include it. I gather based on your advice it is good practice to not use `cbind`. Also, the change should not effect the rest of the code correct? Thank you for your clarification. – N.J Oct 31 '17 at 21:55

1 Answers1

5

cld is in the multcomp package. Reading ?cld gives a clear example of usage with aov. It uses glht, not TukeyHSD. Here is how it works in your example:

library(multcomp)
ph <- glht(Anova_Results, linfct = mcp(ind = "Tukey"))
cld(ph)

Gives:

Group1 Group2 Group3 Group4 Group5 
   "b"   "ab"   "ab"    "a"    "b"
Axeman
  • 32,068
  • 8
  • 81
  • 94