axjack's blog

### axjack is said to be an abbreviation for An eXistent JApanese Cool Klutz ###

統計学実践ワークブック 第20章 分散分析と実験計画法

# 統計学実践ワークブック ####
# 第20章 分散分析と実験計画法 ####
# pp.167-172

# 参考
# https://www1.doshisha.ac.jp/~mjin/R/Chap_13/13.html

# [p.167]表20.1 ####
A1 <- c(9.7,8.7,10.2,11.3,11.2,11.7)
A2 <- c(9.8,11.8,13.1,10.9,11.3,10.3)
A3 <- c(9.2,10.0,10.2,8.9,10.4,10.6)
A4 <- c(13.1,12.6,12.7,12.6,14.3,12.9)
A5 <- c(10.8,10.5,13.0,11.9,13.4,10.3)

A <- rep(paste0('A',1:5), rep(6,5))
y <- c(A1,A2,A3,A4,A5)
df <- data.frame(A, y)
df |> head()

dev.off()
par(mfcol = c(1,1))
boxplot(y~A, data = df, col = "lightblue")
aov(y~A, data=df) |> summary()



# [p.170]表20.4 ####
A1 <- c(339,419,289,132,178,202)  
A2 <- c(138,142,206,173,192,166)
A3 <- c(190,201,120,59,77,25)
A4 <- c(197,126,204,157,168,194)
A5 <- c(423,384,312,381,283,247)
A6 <- c(368,383,345,235,230,171)

A <- rep(paste0('A',1:6), rep(6,6))
B <- rep(paste0('B',1:2), rep(3,2))
y <- c(A1,A2,A3,A4,A5,A6)
df <- data.frame(A,B,y)
df |> head()

par(mfcol = c(1,2))
boxplot(y~A, data = df, col = "lightblue")
boxplot(y~B, data = df, col = "lightgreen")
aov(y~A*B, data=df) |> summary()



# [p.172]表20.6 ####
A1 <- c(5.2,12.3,7.1,20.5,9.4)
A2 <- c(3.8,11.3,7.2,18.5,9.0)  
A3 <- c(7.2,15.3,10.6,25.3,11.1)
A4 <- c(3.5,10.2,8.5,20.2,10.7)

A <- rep(paste0('A',1:4),rep(5,4))
B <- rep(paste0('B',1:5),4)
y <- c(A1,A2,A3,A4)
df <- data.frame(A,B,y)

df |> head()
dev.off()
par(mfcol = c(1,1))
boxplot(y~A, data = df, col = "lightblue")

print("ブロック因子を導入した分散分析表の例")
aov(y~A+B, data=df) |> summary()

print("ブロック因子を導入しない場合の1元配置分散分析表の例")
aov(y~A, data=df) |> summary()

axjack is said to be an abbreviation for An eXistent JApanese Cool Klutz.