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

Enable single Surv object as the reponse in a formula for orsf() #11

Closed
hfrick opened this issue Nov 1, 2022 · 3 comments
Closed

Enable single Surv object as the reponse in a formula for orsf() #11

hfrick opened this issue Nov 1, 2022 · 3 comments

Comments

@hfrick
Copy link

hfrick commented Nov 1, 2022

I'd like to use a "pre-made" Surv object as the response in the formula interface. Would it be possible to allow for that? For some context, this is to make it easier to use the aorsf engine in tidymodels' workflow objects.

library(aorsf)
library(survival)

lung_orsf <- na.omit(lung)
lung_orsf$surv <- Surv(lung_orsf$time, lung_orsf$status)
lung_orsf <- lung_orsf[, -c(2,3)]

aorsf::orsf(
  data = lung_orsf,
  formula = surv ~ age + ph.ecog
)
#> Error: formula must have two variables (time & status) as the response

Created on 2022-11-01 with reprex v2.0.2

@bcjaeger
Copy link
Collaborator

bcjaeger commented Nov 1, 2022

Absolutely - that makes sense to me. I will make an update soon.

@hfrick
Copy link
Author

hfrick commented Nov 1, 2022

Awesome, thank you! 🙌

@bcjaeger
Copy link
Collaborator

bcjaeger commented Nov 3, 2022

Should be good to go now. Thank you for the suggestion and the great example!

library(aorsf)
library(survival)

lung_orsf <- na.omit(lung)
lung_orsf$surv <- Surv(lung_orsf$time, lung_orsf$status)
lung_orsf <- lung_orsf[, -c(2,3)]

fit <- orsf(lung_orsf, formula = surv ~ age + ph.ecog)

predict(fit, new_data = lung_orsf[1:5, ])
#>           [,1]
#> [1,] 0.3283840
#> [2,] 0.3673719
#> [3,] 0.3346957
#> [4,] 0.4501146
#> [5,] 0.4982628
orsf_vi_negate(fit)
#>    ph.ecog        age 
#>  0.2265581 -0.0412957
orsf_summarize_uni(object = fit, n_variables = 1)
#> 
#> -- ph.ecog (VI Rank: 1) -----------------------
#> 
#>        |---------------- risk ----------------|
#>  Value      Mean    Median    25th %    75th %
#>   -1.3 0.2740017 0.2493573 0.2267411 0.3259105
#>   0.06 0.3642472 0.3664885 0.3522197 0.3812756
#> 
#>  Predicted risk at time t = 268 for top 1 predictors

Created on 2022-11-02 by the reprex package (v2.0.1)

@bcjaeger bcjaeger closed this as completed Nov 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants