0

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.

RCchelsie
  • 111
  • 6
  • 2
    Basic rules for presenting problem in R: 1) use `library` calls to load needed packages first, 2) present either a dataset, possibly using methods from the "Great reproducible examples in R" Q&A, or a sufficiently detailed description of one. Furthermore, the material at the link suggests that survival models in `tidymodels` are very much a work in progress and my reading of that page is that they are nowhere near offering the features you desire. I suggest you use standard functions from package `survival` and the many ancillary packages that have been developed. – IRTFM Sep 21 '21 at 00:04
  • [How to make a great R reproducible example?](http://stackoverflow.com/questions/5963269) – Tung Sep 21 '21 at 00:13
  • Thanks for the comment. I didn't furnish a reproducible data because it is a theroritical question. As you read in the link, the package didn't look ready in 2020. As in 2021, I didn't find anything newer but I was wondering if someone did. Thanks anyway. – RCchelsie Sep 21 '21 at 17:45

0 Answers0