r - TukeyHSD 错误

标签 r statistics

我有一个如下所示的数据,我尝试执行方差分析并检查所有列之间的差异。它们彼此之间的差异有多大等等。

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

首先我使用以下命令执行方差分析
 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

最佳答案

正如 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 .有一个plot TukeyHSD 类对象的方法(以及 print 方法)。
forplot <- TukeyHSD(anovar, which = 'color')
plot(forplot) 

enter image description here

关于r - TukeyHSD 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32605582/

相关文章:

R 随机森林 : Proximity for new object

r - 如何使用 agrep 获得模糊字符串匹配的精确公共(public) "max.distance"值?

r - dplyr::funs() 软弃用 - 更新以返回变量名称

r - 从推文中提取主题标签

machine-learning - 纠正收集数据中的已知偏差

r - 将@example标记与roxygen2一起使用时的文件位置

r - 具有常见图例的 ggarrange 在 Markdown 中产生额外的空白图

java - 获取我的引擎 Activity 的统计信息

random - Xoshiro/Xoroshiro 和零

python - 如何在 Scikit-learn 中使用 `Dirichlet Process Gaussian Mixture Model`? (n_components?)