登录
首页精彩阅读R语言中的双因素方差分析
R语言中的双因素方差分析
2017-10-31
收藏

R语言中的双因素方差分析

在双因素方差分析中,受试者被分配到两因子的交叉类别组中。以基础安装中的Tooth-

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)



数据分析咨询请扫描二维码

客服在线
立即咨询