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

Correlation Plot: regression line #255

Closed
3 tasks done
npaszty opened this issue Jul 25, 2024 · 8 comments · Fixed by #258
Closed
3 tasks done

Correlation Plot: regression line #255

npaszty opened this issue Jul 25, 2024 · 8 comments · Fixed by #258
Assignees
Labels
bug Something isn't working core low-priority

Comments

@npaszty
Copy link
Contributor

npaszty commented Jul 25, 2024

What happened?

selecting eithr CHG or PCHG for the x-axis biomarker results in error if regression line is included. could not trigger same error from y-axis analysis variable when selecting CHG or PCHG. this is a bug but I don't know what the best approach is since the regression package used is not NEST it's mcr package from CRAN.

sessionInfo()

R version 4.3.1 (2023-06-16)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.3 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/libopenblasp-r0.3.20.so;  LAPACK version 3.10.0

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

time zone: Etc/UTC
tzcode source: system (glibc)

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

other attached packages:
 [1] tidyr_1.3.1                     teal.goshawk_0.1.15.9027        teal.modules.general_0.3.0.9038 ggmosaic_0.3.3                 
 [5] ggplot2_3.5.0                   teal.modules.clinical_0.9.0     tern_0.9.5.9007                 rtables_0.6.9.9002             
 [9] formatters_0.5.8.9000           teal.transform_0.5.0            teal.connectors.rice_0.2.0      teal.connectors.harbour_0.1.1  
[13] teal_0.15.2                     teal.slice_0.5.0                teal.data_0.5.0                 teal.code_0.5.0                
[17] stringr_1.5.1                   sparkline_2.0                   ricepass_1.1.4                  rice_3.0.1                     
[21] magrittr_2.0.3                  goshawk_0.1.17.9003             dplyr_1.1.4                     googlesheets4_1.0.1            
[25] DescTools_0.99.54               shiny_1.8.1.1                  

loaded via a namespace (and not attached):
  [1] rstudioapi_0.16.0      jsonlite_1.8.8         estimability_1.5       farver_2.1.1           rmarkdown_2.26         ragg_1.2.7            
  [7] geepack_1.3.10         fs_1.6.3               vctrs_0.6.5            memoise_2.0.1          askpass_1.2.0          htmltools_0.5.8.1     
 [13] forcats_1.0.0          curl_5.2.1             haven_2.5.4            broom_1.0.5            cellranger_1.1.0       sass_0.4.9            
 [19] bslib_0.7.0            htmlwidgets_1.6.4      fontawesome_0.5.2      emmeans_1.10.0         rootSolve_1.8.2.4      plotly_4.10.4         
 [25] cachem_1.0.8           mime_0.12              lifecycle_1.0.4        teal.widgets_0.4.2     pkgconfig_2.0.3        Matrix_1.6-1.1        
 [31] R6_2.5.1               fastmap_1.1.1          rbibutils_2.2.16       digest_0.6.35          Exact_3.2              colorspace_2.1-0      
 [37] shinycssloaders_1.0.0  textshaping_0.3.7      crosstalk_1.2.1        labeling_0.4.3         fansi_1.0.6            httr_1.4.7            
 [43] compiler_4.3.1         gargle_1.2.1           proxy_0.4-27           bit64_4.0.5            withr_3.0.0            backports_1.4.1       
 [49] logger_0.3.0           MASS_7.3-60.0.1        openssl_2.1.1          gld_2.6.6              tools_4.3.1            robslopes_1.1.3       
 [55] googledrive_2.0.0      httpuv_1.6.15          shinyvalidate_0.1.3    glue_1.7.0             nlme_3.1-163           promises_1.2.1        
 [61] grid_4.3.1             rsconnect_1.2.2        checkmate_2.3.1        generics_0.1.3         gtable_0.3.4           class_7.3-22          
 [67] data.table_1.15.4      lmom_3.0               hms_1.1.3              utf8_1.2.4             ggrepel_0.9.5          pillar_1.9.0          
 [73] later_1.3.2            splines_4.3.1          tern.gee_0.1.3         lattice_0.21-9         renv_1.0.3             survival_3.5-7        
 [79] bit_4.0.5              tidyselect_1.2.1       knitr_1.45             teal.logger_0.2.0.9005 xfun_0.43              expm_0.999-9          
 [85] DT_0.33                stringi_1.8.3          yaml_2.3.8             lazyeval_0.2.2         boot_1.3-29            shinyWidgets_0.8.4    
 [91] evaluate_0.23          tibble_3.2.1           cli_3.6.2              systemfonts_1.0.6      arrow_16.1.0           xtable_1.8-4          
 [97] Rdpack_2.6             munsell_0.5.1          jquerylib_0.1.4        Rcpp_1.0.12            teal.reporter_0.3.1    readxl_1.4.3          
[103] parallel_4.3.1         assertthat_0.2.1       mcr_1.3.3              viridisLite_0.4.2      mvtnorm_1.2-4          scales_1.3.0          
[109] e1071_1.7-14           purrr_1.0.2            rlang_1.1.3            shinyjs_2.1.0

Relevant log output

Warning: Error in :In argument: `intercept = slope(AVALL2_F2974907, PCHG_ALBUM)[1]`.In group 1: `ACTARM = Cohort 1` and `AVISITCD = BL`.
Caused by error in `mc.deming()`:
! NA/NaN/Inf in foreign function call (arg 4) 
 when evaluating qenv code:
p <- goshawk::g_correlationplot(data = ANL_TRANSPOSED, param_var = "PARAMCD", xaxis_param = "ALBUM", xaxis_var = "PCHG", xvar = "PCHG_ALBUM", yaxis_param = "F2974907", yaxis_var = "AVALL2", yvar = "AVALL2_F2974907", trt_group = "ACTARM", xlim = c(-25, 29), ylim = c(-6, 5), title_text = "Albumin and Flow Cytometry Test F2974907 @ Visits", xaxis_lab = "Albumin PCHG Values", yaxis_lab = "Flow Cytometry Test F2974907 AVALL2 Values", color_manual = c(`Cohort 1` = "#000000", `Cohort 2` = "#3498DB"), shape_manual = c(N = 1,      Y = 2, `NA` = 0), facet_ncol = 6, visit_facet = TRUE, facet = FALSE, facet_var = "ACTARM", reg_line = TRUE, font_size = 20, dot_size = 4, reg_text_size = 7, loq_legend = TRUE, rotate_xlab = TRUE, hline_arb = numeric(0), hline [... truncated]
  126: <Anonymous>
  125: stop
  124: [[.qenv.error
  122: <reactive>
  106: plot_r
   97: renderUI
   96: func
   83: renderFunc
   82: output$teal-main_ui-root-visualizations-Correlation_Plot-module-plot-plot_out_main
    1: runApp

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.
@npaszty npaszty added bug Something isn't working low-priority labels Jul 25, 2024
@npaszty
Copy link
Contributor Author

npaszty commented Jul 25, 2024

set to low-priority as it isn't a blocker for now to needing to tag and release.

@donyunardi
Copy link
Contributor

To add more context:

image

Steps to reproduce:

For convenience, here is the error

ℹ In argument: intercept = slope(AVAL_ALT, PCHG_ALT)[1].
ℹ In group 1: TRT01A = Drug X 100mg and AVISITCD = BL.
Caused by error in mc.deming():
! NA/NaN/Inf in foreign function call (arg 4)
when evaluating qenv code:
p <- goshawk::g_correlationplot(data = ANL_TRANSPOSED, param_var = "PARAMCD", xaxis_param = "ALT", xaxis_var = "PCHG", xvar = "PCHG_ALT", yaxis_param = "ALT", yaxis_var = "AVAL", yvar = "AVAL_ALT", trt_group = "TRT01A", xlim = c(-100, 1060933), ylim = c(0, 55), title_text = "Alanine Aminotransferase Measurement and Alanine Aminotransferase Measurement @ Visits", xaxis_lab = "Alanine Aminotransferase Measurement PCHG Values", yaxis_lab = "Alanine Aminotransferase Measurement AVAL Values", color_manual = c(Drug X 100mg = "#1e90ff", Combination 100mg = "#bb9990", Placebo = "#ffa07a"), shape_manual = c(N = 1, Y = 2, NA = 0), facet_ncol = 2, visit_facet = TRUE, facet = FALSE, facet_var = "TRT01A", reg_line = TRUE, font_size = 12, dot_size = 1, reg_text_size = 3, loq_legend = TRUE, rotate_xlab = TRUE, hline_arb = c(10, 30), hline_arb_label = "arb hori label", hline_arb_color = c("red", "blue"), hline_vars = NULL, hline_vars_colors = character(0), hline_vars_labels = " - ALT", vline_arb = c(50, 70), vline_arb_label = "arb vert A", vline_arb_color = c("green", "orange"), vline_vars = NULL, vline_vars_colors = character(0), vline_vars_labels = " - ALT")

Acceptance Criteria

  • Investigate why the error occur
  • If the scope of the solution/fix is bigger than expected (e.g., the issue originates from external package rather than goshawk/teal.goshawk), then refine it into an actionable issue for further assessment.
  • Alternatively, rewrite the plot logic to use more reliable dependency

@npaszty
This seems to be a goshawk issue. The teal module simply sets the reg_line argument to TRUE when the checkbox is ticked. If you agree, please move this issue to goshawk.

@npaszty
Copy link
Contributor Author

npaszty commented Aug 8, 2024

@donyunardi

yes, I think you're right that the mcr error comes from its use in the goshawk package.
I don't know if this is a hallucination or maybe I don't have the right role. I guess if it's a hallucination I can use gh package.
image

@donyunardi
Copy link
Contributor

donyunardi commented Aug 8, 2024

To transfer, it's on the right hand side of the issue:

No worries, I'll move this.

@donyunardi donyunardi transferred this issue from insightsengineering/teal.goshawk Aug 8, 2024
@npaszty
Copy link
Contributor Author

npaszty commented Aug 9, 2024

@donyunardi
well I guess chatGPT made it more complicated than necessary. 🤣

@m7pr m7pr self-assigned this Sep 3, 2024
@m7pr
Copy link
Contributor

m7pr commented Sep 3, 2024

Hey, the code that reproduces the issue, so it's simpler for the person handling the issue (note that between p and p_error objects there is only a difference in reg_line = TRUE / reg_line = FALSE

library(shiny)
library(dplyr)
library(goshawk)
library(teal.code)
library(teal.data)
library(teal.slice)
library(teal)
library(teal.transform)
library(teal.goshawk)
library(formatters)
library(magrittr)
library(rtables)
library(tern)
library(teal.modules.clinical)
library(ggplot2)
library(ggmosaic)
library(teal.modules.general)
library(DescTools)
library(random.cdisc.data)
library(stringr)
library(sparkline)
library(DescTools)
library(magrittr)
library(dplyr)
library(random.cdisc.data)
library(stringr)
library(sparkline)

`%make_label%` <- function(lhv, label) {
  attr(lhv, "label") <- label
  lhv
}

`%keep_label%` <- function(lhv, rhv) {
  attributes(lhv) <- attributes(rhv)
  lhv
}

ADSL <- radsl(seed = 1)
ADLB <- radlb(ADSL, seed = 1)
exclude_l2 <- c("")
exclude_chg <- c("")
arm_mapping <- list(`A: Drug X` = "Drug X 100mg", `C: Combination` = "Combination 100mg", `B: Placebo` = "Placebo")
ADSL <- ADSL %>% filter(ITTFL == "Y") %>% mutate(TRTORD = case_when(TRT01P == "A: Drug X" ~ 1, TRT01P == "C: Combination" ~ 2, TRT01P == "B: Placebo" ~ 3, TRUE ~ as.numeric(NA)), TRTORD = TRTORD %make_label% "Treatment Order", TRT01P = as.character(arm_mapping[match(TRT01P, names(arm_mapping))]), TRT01P = factor(ARM) %>% reorder(TRTORD), TRT01P = TRT01P %make_label% "Planned Treatment for Period 01")
char_vars_adsl <- names(Filter(isTRUE, sapply(ADSL, is.character)))
ADSL <- ADSL %>% mutate_at(char_vars_adsl, factor)
ADLB_SUBSET <- ADLB %>% filter(!is.na(AVAL)) %>% filter(ITTFL == "Y" & toupper(AVISIT) %like any% c("SCREEN%", "BASE%", "%WEEK%", "%FOLLOW%")) %>% select(c("STUDYID", "USUBJID", "ITTFL", "ARM", "ARMCD", "ACTARM", "ACTARMCD", "TRT01P", "TRT01A", "AVISIT", "AVISITN", "ADY", "PARAM", "PARAMCD", "AVAL", "AVALU", "BASE", "CHG", "PCHG", "ANRLO", "ANRHI", "LBSTRESC", "SEX", "RACE", "LOQFL")) %>% mutate(AVISITCD = case_when(toupper(AVISIT) == "SCREENING" ~ "SCR", toupper(AVISIT) == "BASELINE" ~ "BL", grepl("WEEK", 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        toupper(AVISIT)) ~ paste("W", trimws(substr(AVISIT, start = 6, stop = stringr::str_locate(AVISIT, "DAY") - 1))), grepl("FOLLOW", toupper(AVISIT)) ~ "FU", TRUE ~ as.character(NA)), AVISITCDN = case_when(AVISITCD == "SCR" ~ -2, AVISITCD == "BL" ~ 0, grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]+", "", AVISITCD)) * 7, AVISITCD == "FU" ~ 100, TRUE ~ as.numeric(NA)), TRTORD = case_when(TRT01P == "A: Drug X" ~ 1, TRT01P == "C: Combination" ~ 2, TRT01P == "B: Placebo" ~ 3, TRUE ~ as.numeric(NA)), LOQFL = if_else(as.character(LOQFL) == 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          "Y", as.character(LOQFL), "N"), BASE2 = NA, CHG2 = NA, PCHG2 = NA) %>% rowwise() %>% group_by(PARAMCD) %>% mutate(LBSTRESC = ifelse(USUBJID %in% sample(USUBJID, 1, replace = TRUE), paste("<", round(runif(1, min = 25, max = 30))), LBSTRESC)) %>% mutate(LBSTRESC = ifelse(USUBJID %in% sample(USUBJID, 1, replace = TRUE), paste(">", round(runif(1, min = 70, max = 75))), LBSTRESC)) %>% ungroup()
attr(ADLB_SUBSET[["LBSTRESC"]], "label") <- "Character Result/Finding in Std Format"
attr(ADLB_SUBSET[["ANRLO"]], "label") <- "Analysis Normal Range Lower Limit"
attr(ADLB_SUBSET[["ANRHI"]], "label") <- "Analysis Normal Range Upper Limit"
PARAM_MINS <- ADLB_SUBSET %>% select(USUBJID, PARAMCD, AVAL) %>% group_by(PARAMCD) %>% summarise(AVAL_MIN = min(AVAL, na.rm = TRUE), .groups = "drop") %>% mutate(PARAMCD = PARAMCD %make_label% "Parameter Code")
ADLB_SUPED1 <- ADLB_SUBSET %>% mutate(BASE2 = ifelse(toupper(AVISIT) == "SCREENING" & is.na(BASE2), AVAL, BASE2) %keep_label% BASE2) %>% mutate(CHG2 = ifelse(toupper(AVISIT) == "SCREENING" & is.na(CHG2), 0, CHG2) %keep_label% CHG2) %>% mutate(PCHG2 = ifelse(toupper(AVISIT) == "SCREENING" & is.na(PCHG2), 0, PCHG2) %keep_label% PCHG2) %>% mutate(BASE = ifelse(toupper(AVISIT) == "BASELINE" & is.na(BASE), AVAL, BASE) %keep_label% BASE) %>% mutate(CHG = ifelse(toupper(AVISIT) == "BASELINE" & is.na(CHG), 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                            0, CHG) %keep_label% CHG) %>% mutate(PCHG = ifelse(toupper(AVISIT) == "BASELINE" & is.na(PCHG), 0, PCHG) %keep_label% PCHG) %>% mutate(TRTORD = TRTORD %make_label% "Treatment Order")
ADLB_SUPED2 <- inner_join(PARAM_MINS, ADLB_SUPED1, by = "PARAMCD")[, union(names(ADLB_SUPED1), names(PARAM_MINS))] %>% mutate(AVALL2 = ifelse(PARAMCD %in% exclude_l2, AVAL, ifelse(PARAMCD %in% exclude_chg, NA, ifelse(AVAL == 0 & AVAL_MIN > 0, log2(AVAL_MIN/2), ifelse(AVAL == 0 & AVAL_MIN <= 0, NA, ifelse(AVAL > 0, log2(AVAL), NA))))) %make_label% "Log2 of AVAL") %>% mutate(BASEL2 = ifelse(PARAMCD %in% exclude_l2, BASE, ifelse(PARAMCD %in% exclude_chg, NA, ifelse(BASE == 0 & AVAL_MIN > 0, log2(AVAL_MIN/2), 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   ifelse(BASE == 0 & AVAL_MIN <= 0, NA, ifelse(BASE > 0, log2(BASE), NA))))) %make_label% "Log2 of BASE") %>% mutate(BASE2L2 = ifelse(PARAMCD %in% exclude_l2, BASE2, ifelse(PARAMCD %in% exclude_chg, NA, ifelse(BASE2 == 0 & AVAL_MIN > 0, log2(AVAL_MIN/2), ifelse(BASE2 == 0 & AVAL_MIN <= 0, NA, ifelse(BASE2 > 0, log2(BASE2), NA))))) %make_label% "Log2 of BASE2") %>% mutate(AVAL_MIN = AVAL_MIN %make_label% "Minimum AVAL Within PARAMCD")
ADLB <- ADLB_SUPED2 %>% mutate(TRT01P = as.character(arm_mapping[match(TRT01P, names(arm_mapping))]), TRT01P = factor(TRT01P) %>% reorder(TRTORD) %make_label% "Planned Treatment for Period 01", TRT01A = as.character(arm_mapping[match(TRT01A, names(arm_mapping))]), TRT01A = factor(TRT01A) %>% reorder(TRTORD) %make_label% "Actual Treatment for Period 01", LOQFL = LOQFL %make_label% "Limit of Quantification", AVISITCD = factor(AVISITCD) %>% reorder(AVISITCDN) %make_label% "Analysis Visit Window Code", 
                               AVISITCDN = AVISITCDN %make_label% "Analysis Visit Window Code (N)", BASE2 = BASE2 %make_label% "Screening Value", CHG2 = CHG2 %make_label% "Absolute Change from Screening", PCHG2 = PCHG2 %make_label% "Percent Change from Screening")
ADLB_LOQS <- goshawk:::h_identify_loq_values(ADLB, flag_var = "LOQFL")
ADLB <- left_join(ADLB, ADLB_LOQS, by = "PARAM")

# stopifnot(rlang::hash(ADSL) == "6a0d37a2dc4a81d7ff62dd65e4bc324a")
# stopifnot(rlang::hash(ADLB) == "3c8a641b2a2df269fbc095cacf0a4360")

ADLB <- dplyr::inner_join(x = ADLB, y = ADSL[, c("STUDYID", "USUBJID"), drop = FALSE], by = c("STUDYID", "USUBJID"))

ANL <- ADLB %>% dplyr::filter(.data[["PARAMCD"]] %in% union("ALT", "ALT")) %>% dplyr::select(c("USUBJID", "TRT01A", "AVISITCD", "PARAMCD", "PARAM", "CHG", "AVAL", "LOQFL", "LBSTRESC"))
ANL_x <- ANL %>% dplyr::filter(.data[["PARAMCD"]] == "ALT" & !is.na(.data[["CHG"]]))
ANL_x <- dplyr::mutate(ANL_x, LOQFL = "N")
ANL_y <- ANL %>% dplyr::filter(.data[["PARAMCD"]] == "ALT" & !is.na(.data[["AVAL"]]))
ANL_TRANSPOSED <- dplyr::inner_join(ANL_x, ANL_y, by = c("USUBJID", "AVISITCD", "TRT01A"), suffix = c("_ALT", "_ALT"))
ANL_TRANSPOSED <- ANL_TRANSPOSED %>% dplyr::mutate(LOQFL_COMB = case_when(.data[["LOQFL_ALT"]] == "Y" | .data[["LOQFL_ALT"]] == "Y" ~ "Y", .data[["LOQFL_ALT"]] == "N" | .data[["LOQFL_ALT"]] == "N" ~ "N", TRUE ~ "NA"))
attr(ANL_TRANSPOSED[["TRT01A"]], "label") <- attr(ANL[["TRT01A"]], "label")
p <- goshawk::g_correlationplot(
  data = ANL_TRANSPOSED, 
  param_var = "PARAMCD", 
  xaxis_param = "ALT", 
  xaxis_var = "CHG", 
  xvar = "CHG_ALT", 
  yaxis_param = "ALT", 
  yaxis_var = "AVAL", 
  yvar = "AVAL_ALT", 
  trt_group = "TRT01A", 
  xlim = c(-48, 47), 
  ylim = c(0, 55), 
  title_text = "Alanine Aminotransferase Measurement and Alanine Aminotransferase Measurement @ Visits", 
  xaxis_lab = "Alanine Aminotransferase Measurement CHG Values", 
  yaxis_lab = "Alanine Aminotransferase Measurement AVAL Values", 
  color_manual = 
    c(`Drug X 100mg` = "#1e90ff", 
      `Combination 100mg` = "#bb9990", 
      Placebo = "#ffa07a"), 
  shape_manual = c(N = 1, Y = 2, `NA` = 0), 
  facet_ncol = 2, 
  visit_facet = TRUE, 
  facet = FALSE, 
  facet_var = "TRT01A", 
  reg_line = FALSE, 
  font_size = 12, 
  dot_size = 1, 
  reg_text_size = 3, 
  loq_legend = TRUE, 
  rotate_xlab = TRUE, 
  hline_arb = c(10, 30), 
  hline_arb_label = "arb hori label", 
  hline_arb_color = c("red", "blue"), 
  hline_vars = NULL, 
  hline_vars_colors = character(0), 
  hline_vars_labels = " - ALT", 
  vline_arb = c(50, 70), 
  vline_arb_label = "arb vert A", 
  vline_arb_color = c("green", "orange"), 
  vline_vars = NULL, 
  vline_vars_colors = character(0), 
  vline_vars_labels = " - ALT"
)
p_error <- goshawk::g_correlationplot(
  data = ANL_TRANSPOSED, 
  param_var = "PARAMCD", 
  xaxis_param = "ALT", 
  xaxis_var = "CHG", 
  xvar = "CHG_ALT", 
  yaxis_param = "ALT", 
  yaxis_var = "AVAL", 
  yvar = "AVAL_ALT", 
  trt_group = "TRT01A", 
  xlim = c(-48, 47), 
  ylim = c(0, 55), 
  title_text = "Alanine Aminotransferase Measurement and Alanine Aminotransferase Measurement @ Visits", 
  xaxis_lab = "Alanine Aminotransferase Measurement CHG Values", 
  yaxis_lab = "Alanine Aminotransferase Measurement AVAL Values", 
  color_manual = 
    c(`Drug X 100mg` = "#1e90ff", 
      `Combination 100mg` = "#bb9990", 
      Placebo = "#ffa07a"), 
  shape_manual = c(N = 1, Y = 2, `NA` = 0), 
  facet_ncol = 2, 
  visit_facet = TRUE, 
  facet = FALSE, 
  facet_var = "TRT01A", 
  reg_line = TRUE, 
  font_size = 12, 
  dot_size = 1, 
  reg_text_size = 3, 
  loq_legend = TRUE, 
  rotate_xlab = TRUE, 
  hline_arb = c(10, 30), 
  hline_arb_label = "arb hori label", 
  hline_arb_color = c("red", "blue"), 
  hline_vars = NULL, 
  hline_vars_colors = character(0), 
  hline_vars_labels = " - ALT", 
  vline_arb = c(50, 70), 
  vline_arb_label = "arb vert A", 
  vline_arb_color = c("green", "orange"), 
  vline_vars = NULL, 
  vline_vars_colors = character(0), 
  vline_vars_labels = " - ALT"
)

@m7pr
Copy link
Contributor

m7pr commented Sep 3, 2024

The error is cause in the slope function in a subgroup of the population where all values of the CHG_ALT are the sime

  slope <- function(x, y) {
    ratio <- stats::sd(x) / stats::sd(y)
    if (!is.na(ratio) && ratio > 0) {
      reg <- mc.deming(y, x, ratio)
      # return the evaluation of the ratio condition as third value in numeric vector to control
      # downstream processing
      return(c(round(reg$b0, 2), round(reg$b1, 2), !is.na(ratio) & ratio > 0))
    }
    # if ratio condition is not met then assign NA to vector so that NULL condition does not throw
    # the error below
    return(as.numeric(c(NA, NA, NA)))
  }  
  
error_group <-
  ANL_TRANSPOSED %>%  
  filter(TRT01A == "Drug X 100mg" & AVISITCD == "BL")

error_group %>%
  pull(CHG_ALT) %>% 
  table
>   0 
> 133 


slope(error_group$AVAL_ALT, error_group$CHG_ALT)

> Error in mc.deming(y, x, ratio) : 
>  NA/NaN/Inf in foreign function call (arg 4)

I believe it's an disability to create a regression line for the plot that has all values on the same X axis :)
I think we should add an if condition that omits such cases (where one variable is equal to the same value) and does not add a regression line to this one plot

image

@m7pr
Copy link
Contributor

m7pr commented Sep 4, 2024

Created a fix for this issue in this PR and assigned @donyunardi for the review #258

@m7pr m7pr closed this as completed in a86cba8 Sep 4, 2024
@m7pr m7pr closed this as completed in #258 Sep 4, 2024
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 low-priority
Projects
None yet
3 participants