Assignment 5

Two Way ANOVA

宋春林

Group 2; ID: 201328006310005

Data

有一个关于检验毒品强弱的试验,给48只老鼠注射I, II, III三种毒药(因素A),同时有A, B, C, D 4种治疗方案(因素B),这样的试验在每一种因素组合下都重复四次测试老鼠的存活时间(年)。试分析毒药和治疗方案以及它们的交互作用对老鼠存活时间有无显著影响。

H01假设:α1=α2=α3=0,即因素A毒药种类对老鼠存活时间没有影响

Ha1假设:α1,α2和α3不全相等,即因素A毒药种类对老鼠存活时间有影响

H02假设:β1=β2=β3=β4=0,即因素B治疗方案对老鼠存活时间没有影响

Ha2假设:β1,β2,β3和β4不全相等,即因素B治疗方案对老鼠存活时间有影响

H03假设:δ11=δ12=δ13=δ14=δ21=δ22=δ23=δ24=δ31=δ32=δ33=δ34=0,即A因素和B因素没有交互作用

Ha3假设:δ11,δ12,…,δ34不全相等,即A因素和B因素有交互作用

α=0.05

R Script

# 输入数据
rats <- data.frame(time = c(0.39, 0.45, 0.46, 0.43, 0.72, 0.8, 0.78, 0.92, 0.53, 
    0.45, 0.63, 0.56, 0.65, 0.71, 0.66, 0.62, 0.36, 0.29, 0.23, 0.33, 0.42, 
    0.61, 0.79, 1.04, 0.94, 0.85, 0.81, 0.6, 0.76, 0.82, 0.71, 0.65, 0.22, 0.31, 
    0.28, 0.33, 0.65, 0.67, 0.69, 0.78, 0.43, 0.45, 0.54, 0.48, 0.38, 0.36, 
    0.41, 0.33), toxicant = gl(3, 16, 48, labels = c("I", "II", "III")), cure = gl(4, 
    4, 48, labels = c("A", "B", "C", "D")))
# 毒素和治疗方案两因素各自效应分析
op <- par(mfrow = c(1, 2))
plot(time ~ toxicant + cure, data = rats)

plot of chunk unnamed-chunk-1

with(rats, interaction.plot(toxicant, cure, time, trace.label = "cure"))
with(rats, interaction.plot(cure, toxicant, time, trace.label = "toxicant"))

plot of chunk unnamed-chunk-1


# Bartlett Test检查方差齐性
bartlett.test(time ~ toxicant, data = rats)
## 
##  Bartlett test of homogeneity of variances
## 
## data:  time by toxicant
## Bartlett's K-squared = 4.085, df = 2, p-value = 0.1297
bartlett.test(time ~ cure, data = rats)
## 
##  Bartlett test of homogeneity of variances
## 
## data:  time by cure
## Bartlett's K-squared = 6.464, df = 3, p-value = 0.09111

# 方差分析
rats.aov <- aov(time ~ toxicant * cure, data = rats)
summary(rats.aov)
##               Df Sum Sq Mean Sq F value  Pr(>F)    
## toxicant       2  0.304   0.152   14.87 2.0e-05 ***
## cure           3  0.998   0.333   32.47 2.4e-10 ***
## toxicant:cure  6  0.307   0.051    4.99 0.00082 ***
## Residuals     36  0.369   0.010                    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Conclusion Statement

由p值可以判断,拒绝H01和H02假设,即因素A毒素和因素B治疗方案对存活时间有显著影响;同时也拒绝H03假设,即认为因素A和因素B交互作用对老鼠存活时间有显著影响。

See All Assignments by 宋春林