[R] Nested anovas in R not doing what they ought to...

ripley@stats.ox.ac.uk ripley at stats.ox.ac.uk
Mon Jul 15 17:45:56 CEST 2002


What R does *is* what it ought to, namely that which it is documented to.

Now, if you tell us what you wanted it to do, we may be able to help.
For a start, the way to do anovas in R is aov() not lm(), and you probably
want a multistratum aov fit, with an Error term in the formula.

On Thu, 11 Jul 2002, Michael Rennie wrote:
>
> Hi, there
>
> I first sent this e-mail a couple months ago, to no avail.Since I am not a member on your mailing list, so could you please cc: a response to me? I'll be sure to check the list today for replies.
>
> I am currently attempting to perform an ANOVA with both nested and normal factors.  My problem is that R is treating my nested factors the exact same way as it would interaction terms.
>
> My output for the nested model is as follows:
>
> > nested <- anova(lm(ltotinv ~ habitat + fish/lake + habitat:fish + habitat:(la\
> ke %in% fish)))
> > nested
> Analysis of Variance Table
>
> Response: ltotinv
>                   Df  Sum Sq Mean Sq F value    Pr(>F)
> habitat            1 17.0829 17.0829 50.0917 3.083e-09 ***
> fish               1  0.9131  0.9131  2.6774  0.107600
> habitat:fish       1 13.0100 13.0100 38.1488 8.877e-08 ***
> fish:lake          1  1.0256  1.0256  3.0072  0.088599 .
> habitat:fish:lake  1  2.7641  2.7641  8.1051  0.006229 **
> Residuals         54 18.4158  0.3410
> ---lysis of Variance Table
> Signif. codes:  0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1
>
> With just interactions, not nested:
>
> > test <- anova(lm(ltotinv ~ habitat + fish + lake:fish + habitat:fish + fish:h\
> abitat:lake))
> > test
> Analysis of Variance Table
>
> Response: ltotinv
>                   Df  Sum Sq Mean Sq F value    Pr(>F)
> habitat            1 17.0829 17.0829 50.0917 3.083e-09 ***
> fish               1  0.9131  0.9131  2.6774  0.107600
> habitat:fish       1 13.0100 13.0100 38.1488 8.877e-08 ***
> fish:lake          1  1.0256  1.0256  3.0072  0.088599 .
> habitat:fish:lake  1  2.7641  2.7641  8.1051  0.006229 **
> Residuals         54 18.4158  0.3410
> ---
> Signif. codes:  0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1
> >
>
>
> We get the same answer.  The reason I figured this out is because I did this analysis first in SAS, and then tried to reproduce it in R.  It must be something to do with my syntax, I imagine, but I can't see what it is.
>
> Any help anyone has would be greatly appreciated.
>
>
> Sincerely,
>
> Mike Rennie
> M.Sc. Candidate, University of Toronto at Mississauga
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list