2017-02-27 102 views
0

我正在从拉丁方实验进行ANOVA测试。出于某种原因,aov()函数只能识别所使用的3个变量中的2个。R中的单因子方差分析

batch = c(1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5) 
day = c(1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4,5,5,5,5,5) 
ingredient = c('A','B','C','D','E','A','B','C','D','E','A','B','C','D','E','A','B','C','D','E','A','B','C','D','E') 
rxn.time = c(8,11,4,6,4,7,2,9,8,2,1,7,10,6,3,7,3,1,6,8,3,8,5,10,8) 
rxn.exp = data.frame(batch, day, ingredient, rxn.time) 
test.10 = aov(rxn.exp$rxn.time~as.factor(rxn.exp$batch)+as.factor(rxn.exp$day)+as.factor(ingredient)) 
summary(test.10) 

该汇总仅为前2个因子生成输出。我尝试过使用factor()函数,而不是as.factor,以及其他一些尝试让R运行测试,并使用3种不同的变化源加上任何噪声。有人可以解释为什么R不合作,以及如何解决?

回答

0

这只是因为“批次”和“成分”的组合是相同的(如果批次= 1,成分= A等)。如果你使用随机成分,它的作品。例如:

ingredient = LETTERS[sample(1:5, size= length(batch), replace=T)] 
rxn.exp = data.frame(batch=as.factor(batch), day=as.factor(day), ingredient=as.factor(ingredient), rxn.time=rxn.time) 
test.10 = lm(rxn.time~batch+day+ingredient, data=rxn.exp) 
summary(test.10) 

另请注意,我指的是lm函数中的数据框。

+0

非常感谢!我没有意识到我输入了这种模式的成分信息。这解决了我的问题 – Omar123456789