[R] named lmer.models in do.call(anova,models)

Ben Bolker bbolker at gmail.com
Wed Aug 28 15:45:06 CEST 2013


Toth, Denes <toth.denes <at> ttk.mta.hu> writes:

> 
> 
> Sorry, I missed to attach the sessionInfo, here it goes:
> 
> > sessionInfo()
> R version 3.0.1 (2013-05-16)
> Platform: x86_64-pc-linux-gnu (64-bit)
> 
[snip]
> other attached packages:
> [1] lme4_1.1-0      Matrix_1.0-12   lattice_0.20-15

[snip]

> > Consider the following example:
> >
> > library(lme4)
> > models <- list(
> >     lmer(Reaction ~ Days + (1| Subject), sleepstudy),
> >     lmer(Reaction ~ Days + (Days | Subject), sleepstudy))
> > #
> > # models is an unnamed list, do.call works (although with warning):
> > do.call(anova, models)
> > #
> > # after labeling the models, do.call gives an error:
> > names(models) <- c("randomIC", "randomSlope")
> > do.call(anova, models)
> > #
> > # without do.call, anova works fine:
> > anova(models[[1]], models[[2]])
> >
> >
> > Is there a possibility to use do.call(anova, models) on named lmer-models?
> >

  This is more appropriate for the r-sig-mixed-models at r-project.org
list, or for https://github.com/lme4/lme4/issues

  The short answer is that this isn't super-easy because the
S3 anova() method assumes that the first argument is called 'object'.
Various workarounds would be possible -- the simplest would be
to set rownames() on the returned object.  We could consider
adding a 'names' argument to the function ...

  Ben Bolker



More information about the R-help mailing list