I'm trying to convert some very old modeling scripts to a tidymodels workflow. I know that stepwise regression isn't ideal, and certainly if I knew my data better I could make more intelligent choices. Are there any tutorials you recommend that would help me come up with a more modern approach to the following (totally ridiculous!) problem:
library(tidyverse)
mtcars <- mtcars
all_interactions <- expand.grid(names(mtcars)[-1],
(names(mtcars)[-1])) %>%
filter(Var1 != Var2) %>%
mutate(interact = paste0("(", Var1, " * ", Var2, ")")) %>%
pull(interact) %>%
paste0(sep = " + ") %>%
paste0(collapse = "") %>%
substr(1, nchar(.)-3)
kitchen_sink <- formula(paste0("mpg ~ ",
paste0(names(mtcars)[-1], collapse = " + "), " + ",
all_interactions))
k <- log(nrow(mtcars))
library(MASS)
step_return <- stepAIC(object = lm(mtcars,
formula = formula("mpg ~ 1")),
scope = list(lower = formula("mgp ~ 1"),
upper = kitchen_sink),
k = k)
Basically, a tidymodels tutorial that could be referenced to answer this question: