R:How 使用 cld 函数从单向方差分析中获取结果

R:How to Use cld Function to Get Results from One-Way Anova

所以我已经将 multcompmultcompview 包安装到 RStudio;但是,当我去使用 cld 函数时,我不断收到此错误

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

我的数据如下:

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)

cld 的正确格式应该是什么?我希望结果从最低到最高均值,然后在其下方以字母形式进行成对比较。

cldmultcomp 包中。阅读 ?cld 给出了 aov 用法的清晰示例。它使用 glht,而不是 TukeyHSD。这是它在您的示例中的工作方式:

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

给出:

Group1 Group2 Group3 Group4 Group5 
   "b"   "ab"   "ab"    "a"    "b"