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

Unobserved factor levels no longer appear to work to indicate no censoring #89

Closed
erikvona opened this issue Feb 7, 2023 · 2 comments · Fixed by #99
Closed

Unobserved factor levels no longer appear to work to indicate no censoring #89

erikvona opened this issue Feb 7, 2023 · 2 comments · Fixed by #99

Comments

@erikvona
Copy link

erikvona commented Feb 7, 2023

When no patients have been censored, this Stack Overflow answer indicates that as long as the first level of the factor is censoring, cuminc will work properly, even if that level has not been observed.

However, this no longer appears to be the case. Example from the linked question:

library(tidycmprsk)

data <- 
  trial %>%
  dplyr::mutate(
    death_cr_new = 
      dplyr::case_when(
        death_cr=="censor" ~ 2,
        death_cr=="death from cancer" ~ 2,
        death_cr=="death other causes" ~ 3
      ) %>%
      factor(levels = 1:3)
  )

data$death_cr_new %>% table()
#> .
#>   1   2   3 
#>   0 145  55

cuminc(Surv(ttdeath, death_cr_new) ~ trt, data)
#> 
#> ── cuminc() ────────────────────────────────────────────────────────────────────
#> • Failure type "3"
#> strata   time   n.risk   estimate   std.error   95% CI          
#> Drug A   5.00   97       0.010      0.010       0.001, 0.050    
#> Drug A   10.0   94       0.021      0.015       0.004, 0.066    
#> Drug A   15.0   83       0.083      0.028       0.039, 0.150    
#> Drug A   20.0   61       0.219      0.044       0.140, 0.310    
#> Drug B   5.00   102      0.000      0.000       NA, NA          
#> Drug B   10.0   95       0.030      0.017       0.008, 0.079    
#> Drug B   15.0   75       0.108      0.033       0.055, 0.181    
#> Drug B   20.0   55       0.248      0.048       0.161, 0.346
#> • Tests
#> outcome   statistic   df     p.value    
#> 3         0.032       1.00   0.86

Created on 2023-02-07 with reprex v2.0.2

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.2.2 (2022-10-31 ucrt)
#>  os       Windows 10 x64 (build 19044)
#>  system   x86_64, mingw32
#>  ui       RTerm
#>  language (EN)
#>  collate  Dutch_Netherlands.utf8
#>  ctype    Dutch_Netherlands.utf8
#>  tz       Europe/Berlin
#>  date     2023-02-07
#>  pandoc   2.19.2 @ H:/Programs/RStudio/bin/quarto/bin/tools/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package       * version date (UTC) lib source
#>  backports       1.4.1   2021-12-13 [1] CRAN (R 4.1.2)
#>  broom           1.0.3   2023-01-25 [1] CRAN (R 4.2.2)
#>  broom.helpers   1.11.0  2023-01-06 [1] CRAN (R 4.2.2)
#>  cli             3.6.0   2023-01-09 [1] CRAN (R 4.2.2)
#>  cmprsk          2.2-11  2022-01-06 [1] CRAN (R 4.1.2)
#>  colorspace      2.1-0   2023-01-23 [1] CRAN (R 4.2.2)
#>  digest          0.6.31  2022-12-11 [1] CRAN (R 4.2.2)
#>  dplyr           1.1.0   2023-01-29 [1] CRAN (R 4.2.2)
#>  evaluate        0.20    2023-01-17 [1] CRAN (R 4.2.2)
#>  fansi           1.0.4   2023-01-22 [1] CRAN (R 4.2.2)
#>  fastmap         1.1.0   2021-01-25 [1] CRAN (R 4.0.3)
#>  fs              1.6.0   2023-01-23 [1] CRAN (R 4.2.2)
#>  generics        0.1.3   2022-07-05 [1] CRAN (R 4.1.3)
#>  ggplot2         3.4.0   2022-11-04 [1] CRAN (R 4.2.2)
#>  glue            1.6.2   2022-02-24 [1] CRAN (R 4.1.3)
#>  gt              0.8.0   2022-11-16 [1] CRAN (R 4.2.2)
#>  gtable          0.3.1   2022-09-01 [1] CRAN (R 4.1.3)
#>  gtsummary       1.7.0   2023-01-13 [1] CRAN (R 4.2.2)
#>  hardhat         1.2.0   2022-06-30 [1] CRAN (R 4.1.2)
#>  htmltools       0.5.4   2022-12-07 [1] CRAN (R 4.2.2)
#>  knitr           1.42    2023-01-25 [1] CRAN (R 4.2.2)
#>  lattice         0.20-45 2021-09-22 [2] CRAN (R 4.2.2)
#>  lifecycle       1.0.3   2022-10-07 [1] CRAN (R 4.1.3)
#>  magrittr        2.0.3   2022-03-30 [1] CRAN (R 4.1.3)
#>  Matrix          1.5-3   2022-11-11 [1] CRAN (R 4.2.2)
#>  munsell         0.5.0   2018-06-12 [1] CRAN (R 4.0.3)
#>  pillar          1.8.1   2022-08-19 [1] CRAN (R 4.1.3)
#>  pkgconfig       2.0.3   2019-09-22 [1] CRAN (R 4.0.3)
#>  purrr           1.0.1   2023-01-10 [1] CRAN (R 4.2.2)
#>  R.cache         0.16.0  2022-07-21 [1] CRAN (R 4.1.3)
#>  R.methodsS3     1.8.2   2022-06-13 [1] CRAN (R 4.1.3)
#>  R.oo            1.25.0  2022-06-12 [1] CRAN (R 4.1.3)
#>  R.utils         2.12.2  2022-11-11 [1] CRAN (R 4.2.2)
#>  R6              2.5.1   2021-08-19 [1] CRAN (R 4.1.1)
#>  reprex          2.0.2   2022-08-17 [1] CRAN (R 4.1.3)
#>  rlang           1.0.6   2022-09-24 [1] CRAN (R 4.1.3)
#>  rmarkdown       2.20    2023-01-19 [1] CRAN (R 4.2.2)
#>  rstudioapi      0.14    2022-08-22 [1] CRAN (R 4.1.3)
#>  scales          1.2.1   2022-08-20 [1] CRAN (R 4.1.3)
#>  sessioninfo     1.2.2   2021-12-06 [1] CRAN (R 4.1.2)
#>  stringi         1.7.12  2023-01-11 [1] CRAN (R 4.2.2)
#>  stringr         1.5.0   2022-12-02 [1] CRAN (R 4.2.2)
#>  styler          1.9.0   2023-01-15 [1] CRAN (R 4.2.2)
#>  survival        3.5-0   2023-01-09 [1] CRAN (R 4.2.2)
#>  tibble          3.1.8   2022-07-22 [1] CRAN (R 4.1.3)
#>  tidycmprsk    * 0.2.0   2022-10-03 [1] CRAN (R 4.1.3)
#>  tidyr           1.3.0   2023-01-24 [1] CRAN (R 4.2.2)
#>  tidyselect      1.2.0   2022-10-10 [1] CRAN (R 4.2.2)
#>  utf8            1.2.2   2021-07-24 [1] CRAN (R 4.2.2)
#>  vctrs           0.5.2   2023-01-23 [1] CRAN (R 4.2.2)
#>  withr           2.5.0   2022-03-03 [1] CRAN (R 4.1.3)
#>  xfun            0.36    2022-12-21 [1] CRAN (R 4.2.2)
#>  yaml            2.3.7   2023-01-23 [1] CRAN (R 4.2.2)
#> 
#>  [1] C:/r-checkpoint/no-checkpoint
#>  [2] C:/Program Files/R/R-4.2.2/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────
@ddsjoberg
Copy link
Collaborator

thanks for the report. we'll check it out soon (-ish?)

@erikvona
Copy link
Author

erikvona commented Feb 7, 2023

Thanks! No hurry, I already have a silly workaround: if you add a row with the state set to censored and the time set to NA, it makes sure the censored level doesn't get dropped, while the row gets excluded from the analysis.

I fear I may be partly responsible as well 😅, the bug got introduced here #80, this line is the problem

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