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

[Bug]: tm_t_coxreg crashes when using a factor variable as covariate where some levels were removed by filter #830

Closed
3 tasks done
mthbretscher opened this issue Sep 21, 2023 · 1 comment · Fixed by #831
Assignees
Labels
bug Something isn't working core sme

Comments

@mthbretscher
Copy link

mthbretscher commented Sep 21, 2023

What happened?

Several of teal.modules.clincal do not give meaningful results or show undesired behaviour if the filtered (adsl) dataset they run on contains factor levels that are not present the data.

Examples (with code for tm_t_coxreg):

  • tm_t_coxreg (probably) attempts to estimate coefficients for all factor levels, present or not, resulting in coxph crashing.. Adjustment for variables where some levels have been removed by filtering can currently only be made using stratification (impacting functionality of the module).

In this example, BMRKR2 is chosen as covariate, but after filtering not all factor levels are present, leading to the described error.

adsl <- tmc_ex_adsl
adtte <- tmc_ex_adtte
arm_ref_comp <- list(
  ACTARMCD = list(
    ref = "ARM B",
    comp = c("ARM A", "ARM C")
  ),
  ARM = list(
    ref = "B: Placebo",
    comp = c("A: Drug X", "C: Combination")
  )
)

app <- init(
  data = cdisc_data(
    cdisc_dataset("ADSL", adsl),
    cdisc_dataset("ADTTE", adtte)
  ),
  filter = list(
    ADSL = list(
      BMRKR2 = list(
        selected = c(
          "LOW",
          "MEDIUM"
        )
      )
    )
  ),
  modules = modules(
    tm_t_coxreg(
      label = "Cox Reg.",
      dataname = "ADTTE",
      arm_var = choices_selected(c("ARM", "ARMCD", "ACTARMCD"), "ARM"),
      arm_ref_comp = arm_ref_comp,
      paramcd = choices_selected(
        value_choices(adtte, "PARAMCD", "PARAM"), "OS"
      ),
      strata_var = choices_selected(
        c("COUNTRY", "STRATA1", "STRATA2"), "STRATA1"
      ),
      cov_var = choices_selected(
        c("AGE", "BMRKR1", "BMRKR2", "REGION1"), c("AGE", "BMRKR2")
      ),
      multivariate = TRUE
    )
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}
  • tm_t_coxreg (and I think also tm_t_logistic) by default try to make treatment comparisons based on all defined factor levels in the treatment variable (I think taking the "first" factor level as reference, the others as comparators). This leads to an error ("Current ADSL data does not have observations from the reference and comparison treatments.") in both modules if any of those levels are not present in the filtered dataset. The app user must manually inspect his/her own filters and re-assign comparator/reference/unused factor levels before any regression result is displayed. Dropping non-existing factor levels should solve both these errors and increase usability considerably.
    Of course one could explicitly specify treatment variable levels to be compared at startup (commented out here) - but as soon as the user changes the filter, the error would re-appear..
adsl <- tmc_ex_adsl
adtte <- tmc_ex_adtte
# arm_ref_comp <- list(
#   ACTARMCD = list(
#     ref = "ARM B",
#     comp = c("ARM A", "ARM C")
#   ),
#   ARM = list(
#     ref = "B: Placebo",
#     comp = c("A: Drug X", "C: Combination")
#   )
# )

app <- init(
  data = cdisc_data(
    cdisc_dataset("ADSL", adsl),
    cdisc_dataset("ADTTE", adtte)
  ),
  filter = list(
    ADSL = list(
      ARM = list(
        selected = c(
          "A: Drug X",
          "B: Placebo"
        )
      )
    )
  ),
  modules = modules(
    tm_t_coxreg(
      label = "Cox Reg.",
      dataname = "ADTTE",
      arm_var = choices_selected(c("ARM", "ARMCD", "ACTARMCD"), "ARM"),
      #arm_ref_comp = arm_ref_comp,
      paramcd = choices_selected(
        value_choices(adtte, "PARAMCD", "PARAM"), "OS"
      ),
      strata_var = choices_selected(
        c("COUNTRY", "STRATA1", "STRATA2"), "STRATA1"
      ),
      cov_var = choices_selected(
        c("AGE", "BMRKR1", "BMRKR2", "REGION1"), "AGE"
      ),
      multivariate = TRUE
    )
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}

I posted those two errors together thinking that both of them could be solved by dropping all non-existent factor levels at some point during start of the module..

sessionInfo()

> sessionInfo()
R version 4.2.2 Patched (2022-11-10 r83330)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.6 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/liblapack.so.3

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8       
 [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] cohoRt_0.0.0.9000            realworldPFS_0.0.5          
 [3] dbplyr_2.3.0                 RocheData_3.2.0             
 [5] survival_3.5-3               broom_1.0.3                 
 [7] nestcolor_0.1.2              scda_0.1.6                  
 [9] teal.modules.clinical_0.8.16 tern_0.9.0                  
[11] rtables_0.6.3                formatters_0.5.2            
[13] teal_0.14.0                  teal.transform_0.4.0        
[15] teal.slice_0.4.0             teal.data_0.3.0             
[17] pins_1.1.0                   rlang_1.1.1                 
[19] glue_1.6.2                   lubridate_1.9.2             
[21] magrittr_2.0.3               forcats_1.0.0               
[23] stringr_1.5.0                dplyr_1.1.0                 
[25] purrr_1.0.1                  readr_2.1.4                 
[27] tidyr_1.3.0                  tibble_3.1.8                
[29] ggplot2_3.4.1                tidyverse_1.3.2             
[31] shiny_1.7.4                 

loaded via a namespace (and not attached):
  [1] readxl_1.4.2          backports_1.4.1       lazyeval_0.2.2       
  [4] splines_4.2.2         crosstalk_1.2.0       teal.logger_0.1.3    
  [7] TH.data_1.1-2         tern.gee_0.1.0.9002   digest_0.6.31        
 [10] htmltools_0.5.4       rsconnect_0.8.29      fansi_1.0.4          
 [13] checkmate_2.1.0       memoise_2.0.1         googlesheets4_1.0.1  
 [16] config_0.3.1          tzdb_0.3.0            remotes_2.4.2        
 [19] modelr_0.1.10         teal.code_0.4.1       R.utils_2.12.2       
 [22] sandwich_3.0-2        timechange_0.2.0      colorspace_2.1-0     
 [25] blob_1.2.3            rvest_1.0.3           rappdirs_0.3.3       
 [28] haven_2.5.1           rbibutils_2.2.13      xfun_0.37            
 [31] crayon_1.5.2          jsonlite_1.8.4        zoo_1.8-11           
 [34] geepack_1.3.9         gtable_0.3.1          gargle_1.3.0         
 [37] emmeans_1.8.4-1       R.cache_0.16.0        car_3.1-1            
 [40] abind_1.4-5           scales_1.2.1          mvtnorm_1.1-3        
 [43] DBI_1.1.3             Rcpp_1.0.10           RPostgres_1.4.5      
 [46] viridisLite_0.4.1     xtable_1.8-4          tidyjson_0.3.2       
 [49] bit_4.0.5             htmlwidgets_1.6.1     httr_1.4.4           
 [52] ellipsis_0.3.2        pkgconfig_2.0.3       R.methodsS3_1.8.2    
 [55] sass_0.4.5            utf8_1.2.3            tidyselect_1.2.0     
 [58] later_1.3.0           munsell_0.5.0         cellranger_1.1.0     
 [61] tools_4.2.2           cachem_1.0.6          cli_3.6.0            
 [64] generics_0.1.3        evaluate_0.20         fastmap_1.1.0        
 [67] yaml_2.3.7            knitr_1.42            bit64_4.0.5          
 [70] fs_1.6.1              shinycssloaders_1.0.0 teal.reporter_0.2.1  
 [73] nlme_3.1-162          mime_0.12             R.oo_1.25.0          
 [76] xml2_1.3.3            compiler_4.2.2        rstudioapi_0.14      
 [79] plotly_4.10.1         curl_5.0.0            reprex_2.0.2         
 [82] bslib_0.4.2           stringi_1.7.12        logger_0.2.2         
 [85] lattice_0.20-45       Matrix_1.5-3          styler_1.9.0         
 [88] shinyjs_2.1.0         vctrs_0.5.2           pillar_1.8.1         
 [91] lifecycle_1.0.3       Rdpack_2.4            jquerylib_0.1.4      
 [94] estimability_1.4.1    data.table_1.14.8     httpuv_1.6.9         
 [97] R6_2.5.1              teal.widgets_0.4.0    promises_1.2.0.1     
[100] codetools_0.2-19      MASS_7.3-58.2         assertthat_0.2.1     
[103] fontawesome_0.5.0     shinyWidgets_0.7.6    withr_2.5.0          
[106] multcomp_1.4-23       hms_1.1.2             shinyvalidate_0.1.2  
[109] grid_4.2.2            coda_0.19-4           rmarkdown_2.20       
[112] carData_3.0-5         googledrive_2.0.0

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct.

Contribution Guidelines

  • I agree to follow this project's Contribution Guidelines.

Security Policy

  • I agree to follow this project's Security Policy.
@mthbretscher mthbretscher added the bug Something isn't working label Sep 21, 2023
@mhallal1
Copy link
Collaborator

Tagging the experts on this topic @edelarua and @Melkiades

@mthbretscher mthbretscher changed the title [Bug]: tm_t_coxreg and other modules crash when using a factor variable as covariate where some levels were removed by filter [Bug]: tm_t_coxreg crashes when using a factor variable as covariate where some levels were removed by filter Sep 21, 2023
@edelarua edelarua self-assigned this Sep 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working core sme
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants