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]: passing control_riskdiff() to riskdiff in tabulate_rsp_subgroups() and tabulate_survival_subgroups() behaves unexpectedly #1386

Closed
3 tasks done
adcascone opened this issue Jan 30, 2025 · 4 comments · Fixed by #1387
Assignees
Labels
bug Something isn't working sme

Comments

@adcascone
Copy link

adcascone commented Jan 30, 2025

What happened?

Hello,

I was working through the examples included in the "Tabulate binary response by subgroup" reference site and I noticed that manipulating the pct argument in the control_riskdiff() function that is passed to the riskdiff argument of tabulate_rsp_subgroups() does not behave as expected.

Specifically, I would expect that setting pct=TRUE would return the outputs as percentages, and setting pct=FALSE would not return percentages. However, the outputs are identical regardless of whether pct is TRUE or FALSE.

Image

Am I misguided/should the outputs above be identical? I'm seeing the same behaviors when I work through the examples in the "Tabulate survival duration by subgroup" reference site and manipulate control_riskdiff()'s arguments in the tabulate_survival_subgroups() function in a similar manner to what I've described here for tabulate_rsp_subgroups() as well.

Thank you for clarifying this!

Here is the code I ran, for replication purposes:

library(tern)
library(dplyr)
library(forcats)

adrs <- tern_ex_adrs
adrs_labels <- formatters::var_labels(adrs)

adrs_f <- adrs %>%
  filter(PARAMCD == "BESRSPI") %>%
  filter(ARM %in% c("A: Drug X", "B: Placebo")) %>%
  droplevels() %>%
  mutate(
    # Reorder levels of factor to make the placebo group the reference arm.
    ARM = fct_relevel(ARM, "B: Placebo"),
    rsp = AVALC == "CR"
  )
formatters::var_labels(adrs_f) <- c(adrs_labels, "Response")

# Unstratified analysis.
df <- extract_rsp_subgroups(
  variables = list(rsp = "rsp", arm = "ARM", subgroups = c("SEX", "BMRKR2")),
  data = adrs_f
)

basic_table() %>%
  tabulate_rsp_subgroups(
    df,
    riskdiff = control_riskdiff(
      arm_x = levels(df$prop$arm)[1],
      arm_y = levels(df$prop$arm)[2],
      pct = TRUE
    )
  )

basic_table() %>%
  tabulate_rsp_subgroups(
    df,
    riskdiff = control_riskdiff(
      arm_x = levels(df$prop$arm)[1],
      arm_y = levels(df$prop$arm)[2],
      pct = FALSE
    )
  )

sessionInfo()

R version 4.4.2 (2024-10-31)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 20.04.6 LTS

Matrix products: default
BLAS/LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.8.so;  LAPACK version 3.9.0

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

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

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

other attached packages:
[1] forcats_1.0.0      dplyr_1.1.4        tern_0.9.6         rtables_0.6.10     magrittr_2.0.3     formatters_0.5.9  

loaded via a namespace (and not attached):
 [1] Matrix_1.7-1      gtable_0.3.6      compiler_4.4.2    tidyselect_1.2.1  tidyr_1.3.1       splines_4.4.2    
 [7] scales_1.3.0      fastmap_1.2.0     lattice_0.22-6    ggplot2_3.5.1     R6_2.5.1          generics_0.1.3   
[13] rbibutils_2.3     backports_1.5.0   checkmate_2.3.2   tibble_3.2.1      munsell_0.5.1     pillar_1.9.0     
[19] rlang_1.1.4       utf8_1.2.4        broom_1.0.7       stringi_1.8.4     cli_3.6.3         withr_2.5.2      
[25] Rdpack_2.6.1      digest_0.6.37     grid_4.4.2        rstudioapi_0.17.1 lifecycle_1.0.4   vctrs_0.6.5      
[31] glue_1.8.0        survival_3.7-0    fansi_1.0.6       colorspace_2.1-1  purrr_1.0.2       tools_4.4.2      
[37] pkgconfig_2.0.3   htmltools_0.5.8.1

Relevant log output

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.
@adcascone adcascone added the bug Something isn't working label Jan 30, 2025
@adcascone adcascone changed the title [Bug]: passing control_riskdiff() to riskdiff in tabulate_rsp_subgroups() behaves unexpectedly [Bug]: passing control_riskdiff() to riskdiff in tabulate_rsp_subgroups() and tabulate_survival_subgroups() behaves unexpectedly Jan 30, 2025
@edelarua edelarua self-assigned this Jan 30, 2025
@edelarua edelarua added the sme label Jan 30, 2025
@edelarua
Copy link
Contributor

edelarua commented Jan 30, 2025

Thanks for bringing this to our attention! I have opened a PR here that will fix this issue once merged in.

@adcascone
Copy link
Author

Thank you, @edelarua!

@edelarua
Copy link
Contributor

Hi @adcascone,

The fix for this issue is now available in the latest development version of tern. You can download the development version from GitHub using the following line of code:

pak::pak("insightsengineering/tern")

Thanks!

@shajoezhu
Copy link
Contributor

let's revisit issue #1181 as well

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

Successfully merging a pull request may close this issue.

3 participants