2017-02-27 111 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