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.
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"