[R] [PS] Two Way ANOVA
Rolf Turner
r.turner at auckland.ac.nz
Thu Mar 20 02:00:43 CET 2008
On 20/03/2008, at 12:54 PM, David Mackovjak wrote:
> I do have the values for each individual values for each cell. They
> are as follows:
>
> N(0) N(20)
> 4.48 5.76
> 4.52 5.64
> 4.63 5.78
> 4.70 7.01
> 4.65 7.11
> 4.57 7.02
> 5.21 5.88
> 5.23 5.82
> 5.38 5.73
> 5.88 6.26
> 5.98 6.26
> 5.91 6.37
>
> So how would I go about this then?
(1) Assign to ``yield'' the foregoing 24 values.
(2) Set up a factor ``nitro'' giving the corresponding levels of
nitrogen
(e.g. with labels ``n0'' and ``n20'' --- rather than ``1'' and
``2'' to
be more evocative and to make it clear that the value of
``nitro'' are
***not*** numeric!).
(3) Likewise set up a factor ``sulfur'' with labels, say ``s0'',
``s3'', ``s6'', ``s9''.
Note that yield is a numeric vector of length 24, nitro and
sulfur are
factors (with 2 and 4 levels respectively) also (of course!) of
length 24.
(4) Fit your linear model:
fit <- lm(yield ~ nitro*sulfur)
(5) Do your analysis of variance:
anova(fit)
(6) Check that the anova assumptions seem to be OK:
plot(fitted(fit),resid(fit)) # Looks pretty good to me.
(7) An interaction plot might be illuminating:
interaction.plot(sulfur,nitro,yield) # The (n20,s3) cell sticks out
like a sore toe.
Since there *is* interaction you might want to treat the modelling
exercise as a one-way
anova on an 8-level factor (one level for each cell). You can create
the appropriate
factor using ``interaction()''. You could fit the one-way model (use
aov() this time;
TukeyHSD demands it!) and then do TukeyHSD() to the result to find
out what really
differs from what.
cheers,
Rolf Turner
######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
More information about the R-help
mailing list