[R] Anova over a list of models
Schalk Heunis
schalk.heunis at enerweb.co.za
Sun Sep 6 14:16:12 CEST 2009
Jeroen
This seems to work for (1):
anova(myModels[[1]], force(myModels[[2]]))
OR
anova(myModels[[1]], (myModels[[2]]))
I suspect this is about lazy-evaluation, looking at the source code
for anova for mer objects: selectMethod("anova","mer"), something goes
wrong with the sapply to get the names, I think sapply(...,toString)
would work better for this particular case.
For (2), the best solution I could come up with is:
myParameters = lapply(1:length(myModels),function(x){ if(x==1)
paste("myModels[[",x,"]]",sep = "") else
paste("force(myModels[[",x,"]])",sep = "")})
myParStr = toString(paste( myParameters ))
eval(parse(text = paste("anova(",myParStr,")")))
I would have expected do.call(anova, myModels) to work
Hope this helps
Schalk Heunis
On Sat, Sep 5, 2009 at 10:43 PM, Jeroen Ooms<j.c.l.ooms at uu.nl> wrote:
> 2009/9/5 Henrique Dallazuanna <wwwhsd at gmail.com>
>>
>> Try this:
>> anova(myModels[[1]],myModels[[2]])
>>
>> do.call(anova, myModels)
>
> Does this work for you? Both functions are failing here:
>
>> anova(myModels[[1]],myModels[[2]])
> Error in names(mods) <- sapply(as.list(mCall)[c(FALSE, TRUE, modp)],
> as.character) :
> 'names' attribute [6] must be the same length as the vector [2]
>> do.call(anova, myModels)
> Error in as.character.default(X[[1L]], ...) :
> no method for coercing this S4 class to a vector
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list