tidymodels / censored

Parsnip wrappers for survival models
https://censored.tidymodels.org/
Other
123 stars 12 forks source link

add `multi` arg to `survival_prob_coxnet()` #279

Closed hfrick closed 11 months ago

hfrick commented 11 months ago

This is part 1 of #267

This does break multi_predict(type = "survival") temporarily but I think it'll be easier to review when the necessary changes to multi_predict() are coming in the next PR.

library(censored)
#> Loading required package: parsnip
#> Loading required package: survival
lung2 <- lung[-14, ]

set.seed(14)
f_fit <- proportional_hazards(penalty = 0.123) %>%
  set_mode("censored regression") %>%
  set_engine("glmnet") %>%
  fit(Surv(time, status) ~ age + ph.ecog, data = lung2)

pred_multi <- survival_prob_coxnet(f_fit, new_data = lung2[1:3, c("age", "ph.ecog")],
                            eval_time = c(100, 200), penalty = 0.1, multi = TRUE)

# this should have a penalty column
pred_multi$.pred[[1]]
#> # A tibble: 2 × 3
#>   penalty .eval_time .pred_survival
#>     <dbl>      <dbl>          <dbl>
#> 1     0.1        100          0.868
#> 2     0.1        200          0.680

Created on 2023-12-18 with reprex v2.0.2

github-actions[bot] commented 10 months ago

This pull request has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.