Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix output format #284

Merged
merged 4 commits into from
Dec 20, 2023
Merged

Fix output format #284

merged 4 commits into from
Dec 20, 2023

Conversation

hfrick
Copy link
Member

@hfrick hfrick commented Dec 20, 2023

Closes #274 and closes #275

I introduce a wrapper survival_prob_pecRpart() because we want to move away from relying on eval_time added to the spec, see #236.

library(censored)
#> Loading required package: parsnip
#> Loading required package: survival

mod <- decision_tree() %>%
  set_mode("censored regression") %>%
  set_engine("rpart") %>%
  fit(Surv(time, status) ~ ., data = lung)

predict(mod, lung[2,], type = "survival", eval_time = c(100, 500)) %>% str()
#> tibble [1 × 1] (S3: tbl_df/tbl/data.frame)
#>  $ .pred:List of 1
#>   ..$ : tibble [2 × 2] (S3: tbl_df/tbl/data.frame)
#>   .. ..$ .eval_time    : num [1:2] 100 500
#>   .. ..$ .pred_survival: num [1:2] 0.75 0.0739

lung_orsf <- na.omit(lung)
mod <- rand_forest() %>%
  set_mode("censored regression") %>%
  set_engine("aorsf") %>%
  fit(Surv(time, status) ~ ., data = lung_orsf)

predict(mod, lung[2,], type = "survival", eval_time = c(100, 500)) %>% str()
#> tibble [1 × 1] (S3: tbl_df/tbl/data.frame)
#>  $ .pred:List of 1
#>   ..$ : tibble [2 × 2] (S3: tbl_df/tbl/data.frame)
#>   .. ..$ .eval_time    : num [1:2] 100 500
#>   .. ..$ .pred_survival: num [1:2] 0.932 0.35

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

@hfrick hfrick merged commit d8b30c0 into main Dec 20, 2023
8 checks passed
@hfrick hfrick deleted the fix-output-format branch December 20, 2023 17:36
Copy link

github-actions bot commented Jan 4, 2024

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.

@github-actions github-actions bot locked and limited conversation to collaborators Jan 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
1 participant