Skip to content

[Bug]: passing control_riskdiff() to riskdiff in tabulate_rsp_subgroups() and tabulate_survival_subgroups() behaves unexpectedly #1386

@adcascone

Description

@adcascone

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.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingsme

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions