Reputation: 320
Hello I am working with these packages
library(tidyverse)
library(ISLR)
library(boot)
I created a list of various polynomial models and I would like run anova all the models together.
df<- Wage
degrees <- seq(1,5)
Poly.fits <- vector("list", length(degrees))
for (d in degrees){
Poly.fits[[d]]<- lm(wage ~ poly(age,d), data = df)
}
This works
do.call("anova", Poly.fits)
This works as well
anova(Poly.fits[[1]], Poly.fits[[2]], Poly.fits[[3]], Poly.fits[[4]], Poly.fits[[5]], test = "F")
I want to do this based on doing multiple arguments https://statisticsglobe.com/do-call-and-call-functions-in-r/ as found here
do.call("anova", list(Poly.fits, test = "F"))
But this does not work and leads to this error
Error in UseMethod("anova") : no applicable method for 'anova' applied to an object of class "list"
Does anyone know how I could make this work if at all?
Upvotes: 1
Views: 269
Reputation: 320
Onyambu was correct
This works
do.call("anova", c(Poly.fits, test = "F"))
This works as well
invoke("anova", Poly.fits, test = "F")
Upvotes: 3