如何对这些数据进行Tukey的HSD测试?

时间:2019-06-19 20:07:42

标签: r tukey

我正在尝试对我的数据执行Tukey的HSD测试或LSD测试。我有两个因素,收集(2种处理方法)和灌溉(5种处理方法),并且想对每种组合的蔗糖响应进行测试,因此总共进行了10种处理方法。

数据:

structure(list(Collection = structure(c(1L, 1L, 1L, 1L, 1L, 2L
), .Label = c("1", "2"), class = "factor"), Irrigation = structure(c(1L, 
2L, 3L, 4L, 5L, 1L), .Label = c("Rate1", "Rate2", "Rate3", "Rate4", 
"Rate5"), class = "factor"), meanSuc = c(0.585416666666667, 0.5032, 
0.61375, 0.602775, 0.688466666666667, 0.545133333333333)), row.names = 
 c(NA, 
-6L), groups = structure(list(Collection = structure(1:2, .Label = c("1", 
"2"), class = "factor"), .rows = list(1:5, 6L)), row.names = c(NA, 
-2L), class = c("tbl_df", "tbl", "data.frame"), .drop = TRUE), class = 
c("grouped_df", 
"tbl_df", "tbl", "data.frame"))

尝试将处理合并到一列中并使用Agricolae进行测试:

Tukey_data <- dataAvgSucCI %>% 
  mutate(Tukey_ID = paste(Collection, Irrigation, sep="_"))
TukeyAov <- aov(meanSuc ~ Tukey_ID,Tukey_data)
HSD.test(TukeyAov, "Tukey_ID", group=TRUE)

错误消息:

  

if(pvalue [k] <= 0.001)sig [k] <-“ ***”否则为if(pvalue [k] <=
      :         需要TRUE / FALSE的缺失值       另外:警告消息:       在qtukey(1-alpha,ntr,DFerror)中:产生了NaN

如何编辑代码以使其正常工作?

或者我会写出完全不同的东西更好吗?

1 个答案:

答案 0 :(得分:0)

数据必须看起来像这样(一种方差分析):

Collection =  rep(1:2, times = 1, each = 5)
Irrigation = rep(1:5, times = 2, each = 1)
meanSuc = rnorm(10, mean = 0, sd = 1)

d = data.frame(Collection, Irrigation, meanSuc)

fit = aov(meanSuc ~ as.factor(Collection), data=d)

TukeyHSD(fit)

或双向方差分析:

fit2 = aov(meanSuc ~ as.factor(Collection) + as.factor(Irrigation), data = d)

TukeyHSD(fit2)

我认为您喜欢执行两种方差分析。就像AkselA所说的那样,目标变量(meanSuc)没有变化。