I have a code that works if I am using LM but not if I am using a GAM. I guess the that for whatever reason LM looks inside object for the variable and GAM just looks at the names of the object but I do not have a clue.
library(modelr)
library(purrr)
library(mgcv)
dataf <- data(cars)
dataf <- mtcars
df_split <- crossv_mc(dataf,10)
# LM - works
fn_model <- function(df){
lm(mpg ~ wt, data = df)
}
df_split_model <-
df_split %>%
mutate(model = map(train, fn_model)) %>%
print()
# GAM - does not
fn_model <- function(df){
mgcv::gam(mpg ~ wt, data = df)
}
df_split_model <-
df_split %>%
mutate(model = map(train, fn_model)) %>%
print()
#But i can do
gam(mpg~wt,data=mtcars)