I am using mtcars data to show my problem. The following code works fine with glm. It generates new models by adding each variable in the vlist to the model of glm(vs ~ mpg, family = binomial(), data = mtcars.
check_glm <- function(crude, vlist, data, ...){
a <- glm(crude, data = data, family = binomial())
lapply(vlist, function(x) update(a, as.formula(paste0(". ~ . +", x))))
}
check_glm(crude = "vs ~ mpg", vlist = c("am", "hp"), data = mtcars)
However, when I replaced glm with speedglm,
library(speedglm)
check_speedglm <- function(crude, vlist, data, ...){
a <- speedglm(crude, data = data, family = binomial())
lapply(vlist, function(x) update(a, as.formula(paste0(". ~ . +", x))))
}
check_speedglm(crude = "vs ~ mpg", vlist = c("am", "hp"), data = mtcars)
I got:
Error in model.frame.default(formula = vs ~ mpg + am, data = data, drop.unused.levels = TRUE) : argument "data" is missing, with no default.
I think the problem is in the lapply line but I could not work out a solution. Any suggestions to fix this would be appreciated.