## The model matrices are NOT the same when you use the default contrasts.
## You may have inadvertently changed the contrasts that are constructed.
## You are getting the treatment contrasts, which are not contrasts. See
## ?contr.treatment for details.
##> And the model matrix
##> are indeed the same with following commands:
##
##> model.matrix(aov(y~a*b))
##> model.matrix(aov(y~factor(a)*factor(b)))
##
##> then why the type I and III sum of squares are
##> different?
## original query, with spaces inserted for legibility
y <- rnorm(16,10,3)
a <- c(rep(0,8), rep(1,8))
b <- c(rep(0,4), rep(1,4), rep(0,4), rep(1,4))
summary(aov(y ~ b*a), ssType=1)
summary(aov(y ~ b*a), ssType=3)
## With the default contrasts,
options()$contrasts
model.matrix(aov(y~factor(a)*factor(b))) ## orthogonal dummy variables
## change the settings
tmp <- options()$contrasts
tmp[[1]] <- "contr.treatment"
options(contrasts=tmp)
options()$contrasts
model.matrix(aov(y~factor(a)*factor(b))) ## no longer orthogonal
## restore defaults
tmp[[1]] <- "contr.helmert"
options(contrasts=tmp)
options()$contrasts
|