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]: MMRM in the efficacy gallery doesn't work. #26

Open
3 tasks done
jwang-lilly opened this issue Jun 3, 2023 · 2 comments
Open
3 tasks done

[Bug]: MMRM in the efficacy gallery doesn't work. #26

jwang-lilly opened this issue Jun 3, 2023 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@jwang-lilly
Copy link

What happened?

teal.gallery::launch_app("efficacy") starts nicely. All the tab works except MMRM which gives the following error message. Change to Kenward-Roger would produce the similar error message. Default is used for all the selection.

Relevant log output

unused argument (method = "Satterthwaite")
when evaluating qenv code:
anl <- ANL %>% dplyr::filter(ARM %in% c("A: Drug X", "B: Placebo", "C: Combination")) %>% dplyr::mutate(ARM = stats::relevel(ARM, ref = "A: Drug X")) %>% dplyr::mutate(ARM = droplevels(ARM)) %>% df_explicit_na(na_level = "")
ANL_ADSL <- ANL_ADSL %>% dplyr::filter(ARM %in% c("A: Drug X", "B: Placebo", "C: Combination")) %>% dplyr::mutate(ARM = stats::relevel(ARM, ref = "A: Drug X")) %>% dplyr::mutate(ARM = droplevels(ARM)) %>% df_explicit_na(na_level = "")
fit <- tern.mmrm::fit_mmrm(vars = list(response = "AVAL", covariates = NULL, id = "USUBJID", arm = "ARM", visit = "AVISIT"), data = anl, conf_level = 0.95, method = "Satterthwaite", cor_struct = "unstructured", weights_emmeans = "proportional", parallel = TRUE)

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.
@jwang-lilly jwang-lilly added the bug Something isn't working label Jun 3, 2023
@cicdguy cicdguy removed their assignment Jun 4, 2023
@m7pr
Copy link
Contributor

m7pr commented Jul 10, 2023

hey @JianWang2016 what is the output of your sessionInfo()? You can run it after your launch and turn off the teal app. This will be helpful in figuring out what combinations of packages do you have and whether you need to update one of them

@m7pr
Copy link
Contributor

m7pr commented Jul 10, 2023

Here is my sessionInfo() for which I get proper fit of the model in MMRM tab

image

R version 4.2.3 (2023-03-15 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)

Matrix products: default

locale:
[1] LC_COLLATE=English_Europe.utf8  LC_CTYPE=English_Europe.utf8    LC_MONETARY=English_Europe.utf8
[4] LC_NUMERIC=C                    LC_TIME=English_Europe.utf8    

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

other attached packages:
 [1] sparkline_2.0                     nestcolor_0.1.2.9001              teal.modules.clinical_0.8.15.9006
 [4] tern_0.8.4.9004                   rtables_0.6.1.9010                formatters_0.5.0.9002            
 [7] teal.modules.general_0.2.15.9026  teal_0.13.0.9006                  teal.transform_0.3.0.9003        
[10] magrittr_2.0.3                    teal.data_0.2.0.9003              shinyTree_0.2.7                  
[13] ggmosaic_0.3.3                    ggplot2_3.4.2                     scda.2022_0.1.4.9008             
[16] scda_0.1.6.9004                   dplyr_1.1.2                       shiny_1.7.4.1                    

loaded via a namespace (and not attached):
  [1] colorspace_2.1-0          ellipsis_0.3.2            rsconnect_0.8.29          rprojroot_2.0.3          
  [5] estimability_1.4.1        mmrm_0.2.2.9028           fs_1.6.2                  rstudioapi_0.15.0        
  [9] remotes_2.4.2             ggrepel_0.9.3             DT_0.28                   fansi_1.0.4              
 [13] mvtnorm_1.2-2             splines_4.2.3             R.methodsS3_1.8.2         cachem_1.0.8             
 [17] knitr_1.43                jsonlite_1.8.7            broom_1.0.5               geepack_1.3.9            
 [21] R.oo_1.25.0               compiler_4.2.3            httr_1.4.6                emmeans_1.8.7            
 [25] backports_1.4.1           assertthat_0.2.1          Matrix_1.5-3              fastmap_1.1.1            
 [29] lazyeval_0.2.2            cli_3.6.1                 later_1.3.1               htmltools_0.5.5          
 [33] tools_4.2.3               gtable_0.3.3              glue_1.6.2                Rcpp_1.0.11              
 [37] jquerylib_0.1.4           styler_1.10.1             vctrs_0.6.2               nlme_3.1-162             
 [41] teal.logger_0.1.1.9007    crosstalk_1.2.0           xfun_0.39                 stringr_1.5.0            
 [45] rbibutils_2.2.13          mime_0.12                 lifecycle_1.0.3           shinyvalidate_0.1.2      
 [49] renv_1.0.0                staged.dependencies_0.2.8 MASS_7.3-58.2             scales_1.2.1             
 [53] promises_1.2.0.1          parallel_4.2.3            tern.gee_0.1.0.9006       TMB_1.9.4                
 [57] yaml_2.3.7                curl_5.0.1                memoise_2.0.1             teal.slice_0.3.0.9005    
 [61] teal.widgets_0.3.0.9003   sass_0.4.6                stringi_1.7.12            desc_1.4.2               
 [65] checkmate_2.2.0           teal.reporter_0.1.1.9016  teal.gallery_0.1.0.9010   Rdpack_2.4               
 [69] rlang_1.1.1               pkgconfig_2.0.3           evaluate_0.21             lattice_0.20-45          
 [73] teal.code_0.3.0.9006      fontawesome_0.5.1         purrr_1.0.1               htmlwidgets_1.6.2        
 [77] cowplot_1.1.1             tidyselect_1.2.0          parallelly_1.36.0         logger_0.2.2             
 [81] R6_2.5.1                  generics_0.1.3            pillar_1.9.0              withr_2.5.0              
 [85] survival_3.5-3            tibble_3.2.1              shinyWidgets_0.7.6        utf8_1.2.3               
 [89] plotly_4.10.2             rmarkdown_2.23            grid_4.2.3                data.table_1.14.8        
 [93] git2r_0.32.0              forcats_1.0.0             digest_0.6.31             tern.mmrm_0.2.2.9005     
 [97] xtable_1.8-4              R.cache_0.16.0            tidyr_1.3.0               httpuv_1.6.11            
[101] R.utils_2.12.2            munsell_0.5.0             viridisLite_0.4.2         bslib_0.5.0              
[105] shinyjs_2.1.0

You can always run remove.packages('package_name') on few packages to remove them, and then install all dependencies of teal.gallery again with below code, run when in R working directory set to teal.gallery repository

  if(!requireNamespace('remotes')) {
    install.packages('remotes')
  }
  if(!requireNamespace('staged.dependencies')) {
    remotes::install_github('openpharma/staged.dependencies')
  }
  
  x <- staged.dependencies::dependency_table(".")
  staged.dependencies::install_deps(x, upgrade = "always")

This is the code I get after Fitting the model in MMRM tab

library(shiny)
library(dplyr)
library(scda)
library(scda.2022)
library(ggplot2)
library(ggmosaic)
library(shinyTree)
library(teal.data)
library(magrittr)
library(teal.transform)
library(teal)
library(teal.modules.general)
library(formatters)
library(rtables)
library(tern)
library(teal.modules.clinical)
library(nestcolor)
library(sparkline)
char_vars_asl <- c("STUDYID", "USUBJID", "SUBJID", "SITEID", "INVID", "INVNAM")
ADSL <- synthetic_cdisc_data("latest")$adsl
adsl_labels <- formatters::var_labels(ADSL, fill = FALSE)
adsl_labels <- c(adsl_labels, AGEGR1 = "Age Group")
ADSL <- ADSL %>%
  mutate(AGEGR1 = factor(case_when(AGE < 45 ~ "<45", AGE >= 45 ~ ">=45"))) %>%
  mutate_at(char_vars_asl, factor)
formatters::var_labels(ADSL) <- adsl_labels
ADQS <- synthetic_cdisc_data("latest")$adqs
adqs_labels <- formatters::var_labels(ADQS, fill = FALSE)
ADQS <- ADQS %>%
  filter(ABLFL != "Y" & ABLFL2 != "Y") %>%
  filter(AVISIT %in% c("WEEK 1 DAY 8", "WEEK 2 DAY 15", "WEEK 3 DAY 22")) %>%
  mutate(AVISIT = as.factor(AVISIT), AVISITN = rank(AVISITN) %>% as.factor() %>% as.numeric() %>% as.factor())
formatters::var_labels(ADQS) <- adqs_labels
message(paste("Reproducibility of data import and preprocessing was not explicitly checked", " ('check = FALSE' is set). Contact app developer if this is an issue.\n"))
stopifnot(rlang::hash(ADSL) == "a09e28572f88ca759bd0a4c38febd757")
stopifnot(rlang::hash(ADQS) == "b77b3f0694b20595b4b9303b19b6ef36")
ADQS <- dplyr::inner_join(x = ADQS, y = ADSL[, c("STUDYID", "USUBJID"), drop = FALSE], by = c("STUDYID", "USUBJID"))
ANL_1 <- ADSL %>% dplyr::select(STUDYID, USUBJID, ARM)
ANL_2 <- ADQS %>%
  dplyr::filter(PARAMCD == "FKSI-FWB") %>%
  dplyr::select(STUDYID, USUBJID, PARAMCD, AVISIT)
ANL_3 <- ADQS %>% dplyr::select(STUDYID, USUBJID, PARAMCD, AVISIT, AVAL)
ANL <- ANL_1
ANL <- dplyr::inner_join(ANL, ANL_2, by = c("STUDYID", "USUBJID"))
ANL <- dplyr::inner_join(ANL, ANL_3, by = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"))
ANL <- ANL %>% formatters::var_relabel(ARM = "Description of Planned Arm", PARAMCD = "Parameter Code", USUBJID = "Unique Subject Identifier", AVISIT = "Analysis Visit", AVAL = "Analysis Value")
ANL_ADSL_1 <- ADSL %>% dplyr::select(STUDYID, USUBJID, ARM)
ANL_ADSL <- ANL_ADSL_1
ANL_ADSL <- ANL_ADSL %>% formatters::var_relabel(ARM = "Description of Planned Arm")
anl <- ANL %>%
  dplyr::filter(ARM %in% c("A: Drug X", "B: Placebo", "C: Combination")) %>%
  dplyr::mutate(ARM = stats::relevel(ARM, ref = "A: Drug X")) %>%
  dplyr::mutate(ARM = droplevels(ARM)) %>%
  df_explicit_na(na_level = "")
ANL_ADSL <- ANL_ADSL %>%
  dplyr::filter(ARM %in% c("A: Drug X", "B: Placebo", "C: Combination")) %>%
  dplyr::mutate(ARM = stats::relevel(ARM, ref = "A: Drug X")) %>%
  dplyr::mutate(ARM = droplevels(ARM)) %>%
  df_explicit_na(na_level = "")
fit <- tern.mmrm::fit_mmrm(vars = list(response = "AVAL", covariates = NULL, id = "USUBJID", arm = "ARM", visit = "AVISIT"), data = anl, conf_level = 0.95, method = "Satterthwaite", cor_struct = "unstructured", weights_emmeans = "proportional", parallel = TRUE)
lyt <- rtables::basic_table(subtitles = "Analysis Variable: AVAL,  Endpoint: FKSI-FWB", main_footer = c("Weights for LS Means: proportional", "Correlation Structure: unstructured", "Adjustment Method: Satterthwaite")) %>%
  rtables::split_cols_by(var = "ARM", ref_group = "A: Drug X") %>%
  rtables::add_colcounts() %>%
  rtables::split_rows_by("AVISIT") %>%
  append_varlabels(ANL, "AVISIT") %>%
  tern.mmrm::summarize_lsmeans(show_relative = "reduction") %>%
  rtables::append_topleft(paste0("  ", structure(3,
    levels = c("BFIALL", "FATIGI", "FKSI-FWB", "FKSI-TSE", "FKSIALL"), class = "factor"
  )))
lsmeans_table <- rtables::build_table(lyt = lyt, df = df_explicit_na(broom::tidy(fit), na_level = ""), alt_counts_df = ANL_ADSL)
lsmeans_table

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants