tidymodels alternatives to stepwise regression

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:

There is a chapter in Feature Engineering and Selection on detecting interaction effects. Code is here.

If you can't identify them prior to modeling, regularized models like glmnet are the best approach.

stepAIC() is ok but we don't have that in tidymodels. caret can do it though.

Awesome, thanks! Yeah, I'm not looking to continue using stepAIC, sounds like glmnet and regularized models are what I need to learn about. The book looks very approachable, thanks so much for linking to it.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.