簡體   English   中英

R中的N向ANOVA

[英]N - way ANOVA in R

我正在根據一個拉丁方實驗進行ANOVA測試。 由於某些原因,aov()函數只能識別使用的3個變量中的2個。

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)

摘要僅針對前兩個因素產生輸出。 我試過只使用factor()函數而不是as.factor以及其他幾種嘗試讓R根據需要使用3種不同的變異源以及任何噪聲來運行測試。 有人可以解釋為什么R不合作以及如何解決嗎?

僅僅是因為“批次”和“成分”的組合相同(如果批次= 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函數中引用了數據框。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM