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

Add support for model_get_n() for tidycrr model objects #143

Closed
ddsjoberg opened this issue Jan 31, 2022 · 7 comments · Fixed by #144
Closed

Add support for model_get_n() for tidycrr model objects #143

ddsjoberg opened this issue Jan 31, 2022 · 7 comments · Fixed by #144

Comments

@ddsjoberg
Copy link
Collaborator

ddsjoberg commented Jan 31, 2022

I can try to add this support at some time if you're in a busy season :)

remotes::install_github("MSKCC-Epi-Bio/tidycmprsk")
library(tidycmprsk)

crr(Surv(ttdeath, death_cr) ~ age + trt, trial) %>%
  gtsummary::tbl_regression(exponentiate = TRUE) %>%
  add_nevent() # number of events (first competing event)
@ddsjoberg ddsjoberg changed the title Add support for add_n() and add_nevent() for tidycrr model objects Add support for add_nevent() for tidycrr model objects Feb 1, 2022
larmarange added a commit that referenced this issue Feb 1, 2022
@larmarange
Copy link
Owner

larmarange commented Feb 1, 2022

Dear @ddsjoberg

Can you please check #144 Does it fix the problem? Would you have some other tests to check that results are as expected?

library(tidycmprsk)
library(broom.helpers)
library(gtsummary)
#> 
#> Attachement du package : 'gtsummary'
#> Les objets suivants sont masqués depuis 'package:broom.helpers':
#> 
#>     all_continuous, all_contrasts
#> L'objet suivant est masqué depuis 'package:tidycmprsk':
#> 
#>     trial

mod <- crr(Surv(ttdeath, death_cr) ~ age + trt, tidycmprsk::trial)
#> 11 cases omitted due to missing values

mod %>% model_get_n()
#> # A tibble: 4 x 4
#>   term        n_obs n_event exposure
#>   <chr>       <dbl>   <dbl>    <dbl>
#> 1 (Intercept)   189     154    3762.
#> 2 age           189     154    3762.
#> 3 trtDrug B      98      83    1888.
#> 4 trtDrug A      91      71    1874.

mod %>%
  tbl_regression(exponentiate = TRUE) %>%
  add_nevent() %>%
  as_kable()
Characteristic Event N HR 95% CI p-value
Age 154 1.01 0.99, 1.03 0.6
Chemotherapy Treatment 154
Drug A
Drug B 1.52 0.88, 2.62 0.13

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

@larmarange larmarange changed the title Add support for add_nevent() for tidycrr model objects Add support for model_get_n() for tidycrr model objects Feb 1, 2022
@larmarange
Copy link
Owner

Hmmmm I'm not sure about the results. For Coxph models, the number of events include all type of events.

If I understand properly crr(), you want only the number of events defined by failure option? Can you clarify?

@larmarange
Copy link
Owner

larmarange commented Feb 1, 2022

I have updated the PR to consider, as the number of events, only status defined by failcode. Is it the expected behaviour?

library(tidycmprsk)
library(broom.helpers)
library(gtsummary)
#> 
#> Attachement du package : 'gtsummary'
#> Les objets suivants sont masqués depuis 'package:broom.helpers':
#> 
#>     all_continuous, all_contrasts
#> L'objet suivant est masqué depuis 'package:tidycmprsk':
#> 
#>     trial

mod <- crr(Surv(ttdeath, death_cr) ~ age + trt, tidycmprsk::trial)
#> 11 cases omitted due to missing values

mod %>% model_get_n()
#> # A tibble: 4 x 4
#>   term        n_obs n_event exposure
#>   <chr>       <dbl>   <dbl>    <dbl>
#> 1 (Intercept)   189      52    3762.
#> 2 age           189      52    3762.
#> 3 trtDrug B      98      31    1888.
#> 4 trtDrug A      91      21    1874.

mod %>%
  tbl_regression(exponentiate = TRUE) %>%
  add_nevent() %>%
  as_kable()
Characteristic Event N HR 95% CI p-value
Age 52 1.01 0.99, 1.03 0.6
Chemotherapy Treatment 52
Drug A
Drug B 1.52 0.88, 2.62 0.13

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

@larmarange
Copy link
Owner

Side question: should we support tidycuminc models?

@ddsjoberg
Copy link
Collaborator Author

Everything looks flawless! Thank you so much for adding!

@ddsjoberg
Copy link
Collaborator Author

Side question: should we support tidycuminc models?

What did you have in mind? These estimates are not regression models; they are more like the KM results from survival::survfit().

I also wrote a gtsummary-like function for them and added them to the tidycmprsk package.
https://mskcc-epi-bio.github.io/tidycmprsk/reference/add_cuminc.html

@larmarange
Copy link
Owner

Thanks for the feedback. It's merged now.

No worry, I didn't look into the details of tidycuminc. If there is no need, that's OK with me.

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

Successfully merging a pull request may close this issue.

2 participants