[英]R : TUKEY following one-way ANOVA
I conducted a one-way ANOVA in R, but I keep getting error messages when I attempt to do a Tukey post-hoc to see which treatments differ from each other. 我在R中进行了单向ANOVA,但是当我尝试进行Tukey事后检查以确定哪些治疗方法彼此不同时,我不断收到错误消息。 (I would like the results to be ranked (a, ab, b, bcd...etc.)
(我希望对结果进行排名(a,ab,b,bcd ......等)
DATA details:
资料详情:
data = "abh2"
data =“abh2”
x = 6 treatments : "treatment"
x = 6次治疗:“治疗”
y= moisture readings "moist" (n=63 per treatment, total=378)
y =水分读数“潮湿”(每次治疗n = 63,总数= 378)
I ran a one-way ANOVA: 我运行了单因子方差分析:
anov <- anova(lm(moist~treatment, data=abh2))
.# RESULTS indicate I can move to a post hoc (p<0.05): 。#结果表明我可以转到事后(p <0.05):
Analysis of Variance Table
Response: moist
Df Sum Sq Mean Sq F value Pr(>F)
treatment 5 1706.3 341.27 25.911 < 2.2e-16 ***
I chose Tukey HSD and tried to run it with 2 methods, but get error messages for both: 我选择了Tukey HSD并尝试使用2种方法运行它,但是获取两者的错误消息:
Built-in R function: 内置R功能:
TukeyHSD(anov)
# ERROR : no applicable method for 'TukeyHSD' applied to an object of class "c('anova', 'data.frame')"
Agricolae package: Agricolae套餐:
HSD.test(anov, "treatment", group=TRUE, console=TRUE)
# ERROR : Error in HSD.test(anov, "treatment", group = TRUE, console = TRUE) :
argument "MSerror" is missing, with no default
I found the MSerror was 我发现了MSerror
1) An "# Old version HSD.test()" (But I've just updated the agricolae package) 1)“#旧版本HSD.test()”(但我刚刚更新了agricolae包)
2) MSerror<-deviance(model)/df 2)MSerror <-deviance(model)/ df
So I tried: 所以我尝试过:
HSD.test(anov, "treatment", MSerror=deviance(moist)/5, group=TRUE, console=TRUE)
*but still* # ERROR: $ operator is invalid for atomic vectors
Could anyone help me move ahead from here? 谁能帮助我从这里开始? It seems like a pretty simple problem but I've spent hours on this!
这似乎是一个非常简单的问题,但我花了好几个小时!
Many thanks :) 非常感谢 :)
尝试使用以下代码将治疗指定为一个因素:
abh2$treatment <- factor(abh2$treatment)
Thanks for the feed back Annie-Claude, it got me on the right track that R wasn't recognizing the data as it should. 感谢安妮 - 克劳德的反馈,它让我走上了正确的道路,R没有认识到它应该的数据。
I solved the problem using this code though: 我解决了使用此代码的问题:
library(agricolae)
model<-aov(moist~treatment, data=abh2)
out <- HSD.test(model,"treatment", group=TRUE,console=TRUE)
It appears that the ANOVA command that I was initially using (from R base package), was simply not understood by the Tukey test I was trying to perform afterwards (with the agricolae package). 似乎我最初使用的ANOVA命令(来自R base包),之后我试图执行的Tukey测试(使用agricolae包)根本无法理解。
Take-home message for me: Try to conduct a related string of analyses in the same package! 给我带回家的消息:尝试在同一个包中进行相关的分析!
ps To obtain the p-values: ps获取p值:
summary(model)
they can be converted to a dataframe like so: 它们可以转换为数据帧,如下所示:
as.data.frame( summary(model)[[1]] ) as.data.frame(summary(model)[[1]])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.