×
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
dat <- data.frame(
s=factor(c("s1", "s2", "s3", "s4", "s5", "s6", "s7")),
a=factor(c(rep("a1", 4), rep("a2", 3))),
b1c1=c(2,6,5,7,1,2,5), b1c2=c(5,7,9,9,2,1,4), b1c3=c(9,10,13,14,1,5,3),
b2c1=c(6,6,8,10,5,3,4), b2c2=c(3,6,5,8,5,6,6), b2c3=c(6,7,5,6,5,5,9)
)
options(contrasts = c("contr.sum", "contr.sum"))
lmres <- lm(cbind(b1c1, b1c2, b1c3, b2c1, b2c2, b2c3) ~ a, data = dat)
library(car)
bfact <- factor(rep(c("b1", "b2"), c(3, 3)))
cfact <- factor(rep(c("c1", "c2", "c3"), 2))
idata <- data.frame(bfact, cfact)
Anovares <- Anova(lmres, idata = idata , idesign = ~ bfact*cfact, type = 3)
summary(Anovares)
# aovと比較
library(reshape)
dat.aov <- melt(dat, id=c("s", "a"))
b <- c(rep(c("b1", "b2"), each=21))
c <- c(rep(c("c1", "c2", "c3"), each=7), rep(c("c1", "c2", "c3"), each=7))
dat.aov <- data.frame(dat.aov[c(1, 2, 4)], b, c)
names(dat.aov) <- c("s", "a", "result", "b", "c")
summary(aov(result ~ a * b * c + Error(s:a + b:s:a + c:s:a + b:c:s:a), dat.aov))
PR
Comment
Trackback
Trackback URL
Comment form