双因素方差分析:顾名思义就是同时研究两个因素对实验结果影响是否显著的分析,分析的结果可能只有一个因素显著、也可能两个因素都显著或者都不显著。
双因素方差分析的前提同单因素方差分析一样,是建立在三项假定的基础上进行的:
1.样本数据符合正态分布;
2.样本数据满足方差齐性要求;
3.数据之间相互独立。
data('ToothGrowth')
head(ToothGrowth)
## len supp dose
## 1 4.2 VC 0.5
## 2 11.5 VC 0.5
## 3 7.3 VC 0.5
## 4 5.8 VC 0.5
## 5 6.4 VC 0.5
## 6 10.0 VC 0.5
table(ToothGrowth$supp,ToothGrowth$dose)
##
## 0.5 1 2
## OJ 10 10 10
## VC 10 10 10
shapiro.test(ToothGrowth$len)
##
## Shapiro-Wilk normality test
##
## data: ToothGrowth$len
## W = 0.96743, p-value = 0.1091
attach(ToothGrowth)
fangcha <- aov(len~supp*dose)
summary(fangcha)
## Df Sum Sq Mean Sq F value Pr(>F)
## supp 1 205.4 205.4 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
attach(ToothGrowth)
## The following objects are masked from ToothGrowth (pos = 3):
##
## dose, len, supp
interaction.plot(dose,supp,len)
library(gplots)
##
## Attaching package: 'gplots'
## The following object is masked from 'package:stats':
##
## lowess
attach(ToothGrowth)
## The following objects are masked from ToothGrowth (pos = 4):
##
## dose, len, supp
## The following objects are masked from ToothGrowth (pos = 5):
##
## dose, len, supp
plotmeans(len ~ interaction(dose, supp, sep = ""))
library(HH)
## Loading required package: lattice
## Loading required package: grid
## Loading required package: latticeExtra
## Loading required package: multcomp
## Loading required package: mvtnorm
## Loading required package: survival
## Loading required package: TH.data
## Loading required package: MASS
##
## Attaching package: 'TH.data'
## The following object is masked from 'package:MASS':
##
## geyser
## Loading required package: gridExtra
##
## Attaching package: 'HH'
## The following object is masked from 'package:gplots':
##
## residplot
interaction2wt(len ~ dose*supp,data=ToothGrowth)
《R语言实战》(中文版),人民邮电出版社,2013.
视频《R语言与高级医学统计学》.