You can use do.call
to convert a list of any length into a call suitable for a function taking ...
. The only trick here is that anova
expects the first model to be named--that's what the Curry
handles by creating a new function which already has its first argument specified.
Put everything except the first model (call it lm1
) into one list called Models
.
Then:
library(functional)
do.call( Curry(anova, object=lm1), Models )
Example:
> Models <- list( lm(runif(10)~rnorm(10)),lm(runif(10)~rnorm(10)),lm(runif(10)~rnorm(10)) )
> lm1 <- lm(runif(10)~rnorm(10))
> do.call( Curry(anova, object=lm1), Models )
Analysis of Variance Table
Model 1: runif(10) ~ rnorm(10)
Model 2: runif(10) ~ rnorm(10)
Model 3: runif(10) ~ rnorm(10)
Model 4: runif(10) ~ rnorm(10)
Res.Df RSS Df Sum of Sq F Pr(>F)
1 8 0.46614
2 8 0.59522 0 -0.12908
3 8 1.00869 0 -0.41346
4 8 0.81686 0 0.19182
anova(Models2[[1]],Models[[1]])
work? – Hornbackanova
is most useful for nested models. – Janice