Skip to content
Prev 307459 / 398506 Next

car::linearHypothesis Sum of Sqaures Error?

Dear John,
There are two problems here: (1) the covariate isn't balanced; (2) you
didn't pay attention to the contrasts for factors other than c. The default
is contr.treatment, which produces terms whose contrasts are not orthogonal
in the row basis of the design.

So, the following two ANOVAs (not ANCOVAs) give the same result, but the
third doesn't. For balanced data, types I (sequential), II, and III tests
should all be the same.

----------- snip --------------

model.2 <- lm(y~block+a*b*c, data=data)
anova(model.2)
Anova(model.2)
Anova(model.2, type=3) # incorrect

----------- snip --------------

Here's one way to get correct type III tests:

----------- snip --------------

options(contrasts=c("contr.sum", "contr.poly"))
model.3 <- update(model.2)
anova(model.3)
Anova(model.3)
Anova(model.3, type=3) # now all the same

----------- snip --------------
This is a manifestation of the same problem:

----------- snip --------------

linearHypothesis(model.3, c("cB vs. A&C","cA vs. C")) # SS equal to the sum
of the next two

linearHypothesis(model.3, "cB vs. A&C")
linearHypothesis(model.3, "cA vs. C")

----------- snip --------------

It doesn't make sense to ask whether linearHypothesis() does "type II" or
"type III" tests -- it just tests directly specified linear hypotheses
concerning the parameters of the model as parametrized. Anova() can
formulate sets of type II and III linear hypotheses (but for the latter, you
do have to pay attention to the parametrization).

Best,
 John