R_二元配置の分散分析計算式 - RとLinuxと...

RとLinuxと...


R_二元配置の分散分析計算式

Rの備忘録

# 手計算で2要因の分散分析を行う.手計算といっても,掛け算引き算はRに任せる.

# 山上他 心理統計法 p.155 より

dat <- c(8,10,11, 16,14,15, 2,3,4,  6,6,3,  11,12,8,  11,9,7)
dat155 <- data.frame(labB = c(rep("B1",9), rep("B2",9)), 
  labA =  rep(c(rep("A1",3) ,rep("A2", 3),rep("A3",3)),2), 
  data = dat)

# 本当はこれで済むのだが

summary(aov(data ~ labA*labB, data = dat155))

# 上述書の記載どおりに計算してみる

fA <- 3
fB <- 2
N <- 3
(CT <- (sum(dat))^2 / (fA * fB * N))
(SST <- sum(dat^2) - CT)
(SSA <- (sum(dat155[dat155$labA == "A1",3])^2 +   
   sum(dat155[dat155$labA == "A2",3])^2  + 
   sum(dat155[dat155$labA == "A3",3])^2) / (fB*N) - CT)

(SSB <-  (sum(dat155[dat155$labB == "B1",3])^2 + 
  sum(dat155[dat155$labB == "B2",3])^2)   / (fA*N) - CT)

(SSC <- (  
sum(dat155[dat155$labA == "A1" & dat155$labB == "B1",3])^2 +  
sum(dat155[dat155$labA == "A1" & dat155$labB == "B2",3])^2 + 
sum(dat155[dat155$labA == "A2" & dat155$labB == "B1",3])^2 +  
sum(dat155[dat155$labA == "A2" & dat155$labB == "B2",3])^2 +  
sum(dat155[dat155$labA == "A3" & dat155$labB == "B1",3])^2 +  
sum(dat155[dat155$labA == "A3" & dat155$labB == "B2",3])^2 ) 
 / N - CT)

(SSAB <- SSC - (SSA+SSB))

(SSE <- SST - SSC)
 
Link: Rの備忘録(1827d)
Last-modified: 2007-12-06 (木) 14:52:32 (4031d)