Doing do.call anova not working with extra arguments

256 Views Asked by At

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?

1

There are 1 best solutions below

0
On BEST ANSWER

Onyambu was correct

This works

do.call("anova", c(Poly.fits, test = "F"))

This works as well

invoke("anova", Poly.fits, test = "F")