R語言中的雙因素方差分析
Growth資料集為例,隨機分配60只豚鼠,分別採用兩種餵食方法(橙汁或維生素C),各餵食方法中抗壞血酸含量有三種水平(0.5 mg、1 mg或2 mg),每種處理方式組合都被分配10只豚鼠。牙齒長度為因變數
attach(ToothGrowth)
table(supp, dose)
dose
supp 0.5 1 2
OJ 10 10 10
VC 10 10 10
aggregate(len, by = list(supp, dose), FUN = mean)
1 OJ 0.5 13.23
2 VC 0.5 7.98
3 OJ 1.0 22.70
4 VC 1.0 16.77
5 OJ 2.0 26.06
6 VC 2.0 26.14
aggregate(len, by = list(supp, dose), FUN = sd)
1 OJ 0.5 4.459709
2 VC 0.5 2.746634
3 OJ 1.0 3.910953
4 VC 1.0 2.515309
5 OJ 2.0 2.655058
6 VC 2.0 4.797731
fit <- aov(len ~ supp * dose)
summary(fit)
Df Sum Sq Mean Sq F value Pr(>F)
supp 1 205.3 205.3 12.317 0.000894 ***
dose 1 2224.3 2224.3 133.415 < 2e-16 ***
supp:dose 1 88.9 88.9 5.333 0.024631 *
Residuals 56 933.6 16.7
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
視覺化
(1)interaction.plot(dose, supp, len, type = "b", col = c("red", "blue"), pch = c(16, 18),
main = "Interaction between Dose and Supplement Type")
(2)library(HH)
interaction2wt(len ~ supp * dose)