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 data-related args to survival::coxph() #147

Open
Tracked by #109
hfrick opened this issue Feb 2, 2022 · 4 comments
Open
Tracked by #109

Enable data-related args to survival::coxph() #147

hfrick opened this issue Feb 2, 2022 · 4 comments

Comments

@hfrick
Copy link
Member

hfrick commented Feb 2, 2022

Several arguments to survival::coxph() capture variables or variable names which are to be found in the data: id, cluster, istate. Those don't work with censored/parsnip yet:

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

# `id` arg
mod <- coxph(Surv(tstart, tstop, status) ~ age + steroids + strata(sex),
             data = cgd, id = id)

spec <- proportional_hazards() %>%
  set_engine("survival", id = id)
f_fit <- spec %>%
  fit(Surv(tstart, tstop, status) ~ age + steroids + strata(sex),
      data = cgd)
#> Error in model.frame.default(formula = Surv(tstart, tstop, status) ~ age + : invalid type (language) for variable '(id)'

# `cluster` arg
bladder1 <- bladder[bladder$enum < 5, ] 
mod <- coxph(Surv(stop, event) ~ (rx + size + number) * strata(enum),
             cluster = id, bladder1)

# but also possible to provide `cluster` as a vector
mod <- coxph(Surv(stop, event) ~ (rx + size + number) * strata(enum),
             cluster = bladder1$id, bladder1)

spec <- proportional_hazards() %>%
  set_engine("survival", cluster = id)
f_fit <- spec %>%
  fit(Surv(stop, event) ~ (rx + size + number) * strata(enum),
      data = bladder1)
#> Error in model.frame.default(formula = Surv(stop, event) ~ (rx + size + : invalid type (language) for variable '(cluster)'

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

@hfrick
Copy link
Member Author

hfrick commented Feb 2, 2022

For prediction / survival curves: the id column will need to be present in new_data, similar to how the stratification variable needs to be present.

@hfrick hfrick added the bug an unexpected problem or unintended behavior label Feb 2, 2022
@hfrick
Copy link
Member Author

hfrick commented Feb 7, 2022

check id_var() in multilevelmod

@hfrick
Copy link
Member Author

hfrick commented May 5, 2022

tidymodels/parsnip#713 would fix the issue with fitting the model but would still need to solve the issue at prediction time

@hfrick hfrick removed the bug an unexpected problem or unintended behavior label May 6, 2022
@hfrick
Copy link
Member Author

hfrick commented Nov 28, 2023

Also tidymodels/stacks#117 for dealing with parsnip's quosures since tidymodels/parsnip#737 put an end to tidymodels/parsnip#713 mentioned above

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

1 participant