I would like to predict the time to death in a censored type of data using tidymodels, workflows and tuning. I am getting an error message when I build the recipe.
set.seed(123)
n <- 20
train_data <- data.frame(id=1:n,
death_time = rnorm(n, mean = 5, sd = 3),
death_event = sample(c(0,1), n, replace = TRUE),
age = sample(18:30, n, replace=TRUE),
gender = rep(LETTERS[1:2], n/2),
drug = factor(sample(c("X", "Y"), n, replace = TRUE)))
train_data
library(tidymodels)
data_recipe <-
recipe(Surv(time=death_time, event=death_event) ~ ., data = train_data)
Error: No in-line functions should be used here; use steps to define baking actions.
I would like to be able to tune the hyperparameters after that.
tree_spec <- decision_tree(
cost_complexity = tune(),
tree_depth = tune(),
min_n = tune()) %>%
set_engine("rpart")
tree_workflow <-
workflow() %>%
add_recipe(data_recipe) %>%
add_model(tree_spec)
Is there a way to make it work?
I also would like to do other models like regression and random forest. I only found this with tidymodels https://github.com/tidymodels/planning/blob/master/survival-analysis/README.md but it looks like it is still in progress and not sure it would help for the tuning.