我有一个如下所示的数据,我尝试执行ANOVA并检查所有列之间的差异。它们彼此之间有多大差异等。
df<- structure(list(color = structure(c(3L, 4L, 3L, 4L, 4L, 4L, 4L,
4L, 4L, 4L), .Label = c("B", "G", "R", "W"), class = "factor"),
type = 1:10, X1 = c(0.006605138, 0.001165448, 0.006975109,
0.002207839, 0.00187902, 0.002208638, 0.001199808, 0.001162252,
0.001338847, 0.001106317), X2 = c(0.006041392, 0.001639298,
0.006140877, 0.002958169, 0.002744017, 0.003107995, 0.001729594,
0.001582564, 0.001971713, 0.001693236), X3 = c(0.024180351,
0.002189061, 0.027377442, 0.002886651, 0.002816333, 0.003527908,
0.00231891, 0.001695633, 0.00212034, 0.001962923)), .Names = c("color",
"type", "X1", "X2", "X3"), row.names = c(NA, 10L), class = "data.frame")
首先,我使用以下命令执行ANOVA
anovar= aov(type~.,df)
然后汇总输出如下:
summary(anovar)
到目前为止这么好,它表现得很好。但是,当我尝试执行TukeyHSD时,似乎我有结构问题。错误如下。我搜索过,我找不到任何类似的情况。任何评论将不胜感激
TukeyHSD(anovar)
# Error in rep.int(n, length(means)) : unimplemented type 'NULL' in 'rep3'
# In addition: Warning messages:
# 1: In replications(paste("~", xx), data = mf) : non-factors ignored: X1
# 2: In replications(paste("~", xx), data = mf) : non-factors ignored: X2
# 3: In replications(paste("~", xx), data = mf) : non-factors ignored: X3
答案 0 :(得分:2)
正如在TukeyHSD文档的描述中所述,该函数为因子的级别均值与指定的家族式覆盖概率之间的差异创建了一组置信区间。
这意味着您需要在数据集中包含因子才能运行它。因此,如果您按如下方式选择因子,则可以:
> TukeyHSD(anovar, which = 'color') #color is the only categorical data
Tukey multiple comparisons of means
95% family-wise confidence level
Fit: aov(formula = type ~ ., data = df)
$color
diff lwr upr p adj
W-R 4.375 -1.465325 10.21532 0.1121168
您还会收到警告,忽略非因素X1,X2,X3。
要打印TukeyHSD对象,只需保存并使用plot
即可。类TukeyHSD对象有plot
方法(以及print
方法)。
forplot <- TukeyHSD(anovar, which = 'color')
plot(forplot)