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(
paste(
"Disease ~ ",
paste(c(predictors_list, "(1|ID)"), collapse = " + ")
)
)
wflow <- workflow() %>%
add_recipe(recipe) %>%
add_model(model, formula = mixed_effects_formula)
fitted_model <-
fit(
wflow,
data = data_train
)
"Error in eval(predvars, data, env) : object 'Var1' not found"