Feature selection (FS) and workflows in Tidyverse: How to update formula after FS results?

Dear Posit R Community,

I would like to know how to update the formula used in a workflow object during the fitting step, after a feature selection (FS) pre-processing step was performed.
The current issues is that when running the fit function I get "Error in eval(predvars, data, env) : object 'Var1' not found". It happens since the FS extracted that predictor, but the formula still considered it.
I had to add the formula using add_model, since I am working with a linear mixed effect, and so far I could not find a way to set the random effects ("ID") in a recipe object.

Case example:
predictors_list <- c("Var1", "Var2")
recipe <- recipe(dataset)%>% ... %>% step_select_boruta(all_predictors(), outcome = "Disease")

 recipe <-
    recipe %>% add_role("ID", new_role = "predictor")
    mixed_effects_formula <- as.formula(
        "Disease ~ ",
        paste(c(predictors_list, "(1|ID)"), collapse = " + ")
    wflow <- workflow() %>%
      add_recipe(recipe) %>%
      add_model(model, formula = mixed_effects_formula)

  fitted_model <-
      data = data_train

"Error in eval(predvars, data, env) : object 'Var1' not found"

This topic was automatically closed 21 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.