本文是实验设计与分析(第6版,Montgomery著,傅珏生译) 第章随机化区组,拉丁方, 及有关设计4.5节思考题4.18~4.19 R语言解题。主要涉及方差分析,拉丁方。

batch <- c(rep("batch1",5), rep("batch2",5), rep("batch3",5), rep("batch4",5), rep("batch5",5))
oper <- rep(c("oper1", "oper2", "oper3", "oper4", "oper5"),5)
seed <- c("A", "B", "D", "C", "E", "C", "E", "A", "D", "B", "B", "A", "C", "E", "D", "D", "C",
"E", "B", "A", "E", "D", "B", "A", "C")
y1 <- c(8,7,1,7,3)
y2 <- c(11,2,7,3,8)
y3 <- c(4,9,10,1,5)
y4 <- c(6,8,6,6,10)
y5 <- c(4,2,3,8,8)
y <- c(y1,y2,y3,y4,y5)
rocket.data <- data.frame(batch, oper, seed, y)
matrix(rocket.data$seed, nrow=5, byrow=T)
rocket.data
fit <- lm(y~seed+batch+oper, data=rocket.data)
anova(fit)
> anova(fit)Analysis of Variance Table
Response: y
Df Sum Sq Mean Sq F value Pr(>F)
seed 4 141.44 35.360 11.3092 0.0004877 ***
batch 4 15.44 3.860 1.2345 0.3476182
oper 4 12.24 3.060 0.9787 0.4550143
Residuals 12 37.52 3.127
Signif. codes:
0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


batch <- c(rep("batch1",4), rep("batch2",4), rep("batch3",4), rep("batch4",4))
oper <- rep(c("oper1", "oper2", "oper3", "oper4"),4)
seed <- c("C", "D", "A", "B", "B", "C", "D", "A", "A", "B", "C", "D", "D", "A", "B", "C")
y1 <- c(10,14,7,8)
y2 <- c(7,18,11,8)
y3 <- c(5,10,11,9)
y4 <- c(10,10,12,14)
y <- c(y1,y2,y3,y4)
rocket.data <- data.frame(batch, oper, seed, y)
matrix(rocket.data$seed, nrow=4, byrow=T)
rocket.data
fit <- lm(y~seed+batch+oper, data=rocket.data)
anova(fit)
> anova(fit)Analysis of Variance Table
Response: y
Df Sum Sq Mean Sq F value Pr(>F)
seed 3 72.5 24.1667 13.8095 0.004213 **
batch 3 18.5 6.1667 3.5238 0.088519 .
oper 3 51.5 17.1667 9.8095 0.009926 **
Residuals 6 10.5 1.7500
Signif. codes:
0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

