[R-sig-ME] order of models when using anova
Rolf Turner
r.turner at auckland.ac.nz
Thu Feb 20 22:39:24 CET 2014
In general anova() is *not* really quite smart enough. Consider the case
of ordinary garden-variety linear models:
x <- seq(0,1,length=20)
set.seed(42)
y <- rnorm(20)
f1 <- lm(y ~ x)
f2 <- lm(y ~ x + I(x^2))
anova(f2,f1)
This gives a negative degrees of freedom and a negative sum of squares.
The F statistic and p-value are correct however, so the "not quite
smart enough" aspect is really just cosmetic. Still, those negative
values are disconcerting.
It does appear that the anova() function used on "mer" objects is
smarter than anova.lm(). It is hard/impossible to figure out just
*what* is being used when one calls anova(gm2,gm1) because of these
bloody awful obscurantist S4 classes and methods which seem to be
involved here.
Bottom line: In general the appropriate syntax for anova() would appear
to be anova(reduced model, full model) as the OP stated. But for "mer"
objects it doesn't matter.
cheers,
Rolf
On 21/02/14 09:53, Steve Taylor wrote:
> Both ways work. I think anova() is smart enough to figure out which model is the smaller one.
>
> library(lme4)
> example(glmer)
> # Compare these outputs...
> anova(gm1,gm2)
> anova(gm2,gm1)
>
> cheers,
> Steve
> ____________________________________________
>
> Steve Taylor
> Biostatistician
> Faculty of Health and Environmental Sciences
> AUT University
> http://www.aut.ac.nz/profiles/steve-taylor
> ____________________________________________
>
> -----Original Message-----
> From: r-sig-mixed-models-bounces at r-project.org [mailto:r-sig-mixed-models-bounces at r-project.org] On Behalf Of Juliet Hannah
> Sent: Friday, 21 February 2014 5:22a
> To: r-sig-mixed-models at r-project.org
> Subject: [R-sig-ME] order of models when using anova
>
> All,
>
> When using the anova command to compare nested models I thought the order was
>
> anova(reduced model, full model)
>
> Where the 'full model' has more terms.
>
>
> However, looking at the slides on:
>
> http://lme4.r-forge.r-project.org/slides/2009-07-21-Seewiesen/6Interactions-4a4.pdf
>
>
> pg 3 (comparing the model fits), it looks like I had this backward.
>
> Did I have it backward, or is lme4 different, or is the order not important?
>
> Thanks,
>
> Juliet
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-mixed-models at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>
> _______________________________________________
> R-sig-mixed-models at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>
More information about the R-sig-mixed-models
mailing list