Skip to content

Help with three-way anova

2 messages · michael watson (IAH-C), John Fox

#
OK, now I am lost.

I went from using aov(), which I fully understand, to lm() which I
probably don't.  I didn't specify a contrasts matrix in my call to
lm()....

Basically I want to find out if Infected/Uninfected affects the level of
IL.4, and if Vaccinated/Unvaccinated affects the level of IL.4,
obviously trying to separate the effects of Infection from the effects
of Vaccination.

The documentation for specifying contrasts to lm() is a little
convoluted, sending me to the help file for model.matrix.default, and
the help there doesn't really give me much to go on when trying to
figure out what contrasts matrix I need to use...

Many thanks for your help

Mick

-----Original Message-----
From: Federico Calboli [mailto:f.calboli at imperial.ac.uk] 
Sent: 06 April 2005 10:15
To: michael watson (IAH-C)
Cc: r-help
Subject: RE: [R] Help with three-way anova
On Wed, 2005-04-06 at 09:11 +0100, michael watson (IAH-C) wrote:
Incidentally, if you want interaction terms you need 

lm(IL.4 ~ Infected * Vaccinated * Lesions, data)

for all the possible interactions in the model (BUT you need enough
degrees of freedom from the start to be able to do this).
I guess it's all due to the contrast matrix you used. Check with
contrasts() the term(s) in the datafile you use as independent
variables, and change the contrast matrix as you see fit.

HTH,

F
#
Dear Mick,

For a three-way ANOVA, the difference between aov() and lm() is mostly in
the print and summary methods -- aov() calls lm() but in its summary prints
an ANOVA table rather than coefficient estimates, etc. You can get the same
ANOVA table from the object returned by lm via the anova() function. The
problem, however, is that for unbalanced data you'll get sequential sums of
squares which likely don't test hypotheses of interest to you.

If you didn't explicitly set the contrast coding, then the out-of-box
default in R [options("contrasts")] is to use treatment.contr(), which
produces dummy-coded (0/1) contrasts. In this case, the "intercept"
represents the fitted value when all of the factors are at their baseline
levels, and it's probably entirely uninteresting to test whether it is 0.

More generally, however, it seems unreasonable to try to learn how to fit
and interpret linear models in R from the help files. There's a brief
treatment in the Introduction to R manual that's distributed with R, and
many other more detailed treatments -- see
http://www.r-project.org/other-docs.html.

Regards,
 John

--------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox 
--------------------------------