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]: "label_all" dose not work in tabulate_survival_subgroups() #1231

Closed
3 tasks done
fenguoerbian opened this issue Apr 19, 2024 · 2 comments · Fixed by #1232
Closed
3 tasks done

[Bug]: "label_all" dose not work in tabulate_survival_subgroups() #1231

fenguoerbian opened this issue Apr 19, 2024 · 2 comments · Fixed by #1232
Assignees
Labels
bug Something isn't working sme

Comments

@fenguoerbian
Copy link

What happened?

Change label_all in tabulate_survival_subgroups() will not have any actual effect on the resulting table.

example from tabulate_survival_subgroups()'s documentation. One can see that the resulting table still has "All Patients", not "Full Analysis Set" in the first row.

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

adtte <- tern_ex_adtte

# Save variable labels before data processing steps.
adtte_labels <- formatters::var_labels(adtte)

adtte_f <- adtte %>%
    filter(
        PARAMCD == "OS",
        ARM %in% c("B: Placebo", "A: Drug X"),
        SEX %in% c("M", "F")
    ) %>%
    mutate(
        # Reorder levels of ARM to display reference arm before treatment arm.
        ARM = droplevels(fct_relevel(ARM, "B: Placebo")),
        SEX = droplevels(SEX),
        AVALU = as.character(AVALU),
        is_event = CNSR == 0
    )
labels <- c(
    "ARM" = adtte_labels[["ARM"]],
    "SEX" = adtte_labels[["SEX"]],
    "AVALU" = adtte_labels[["AVALU"]],
    "is_event" = "Event Flag"
)
formatters::var_labels(adtte_f)[names(labels)] <- labels

df <- extract_survival_subgroups(
    variables = list(
        tte = "AVAL",
        is_event = "is_event",
        arm = "ARM", subgroups = c("SEX", "BMRKR2")
    ),
    data = adtte_f
)
df

df_grouped <- extract_survival_subgroups(
    variables = list(
        tte = "AVAL",
        is_event = "is_event",
        arm = "ARM", subgroups = c("SEX", "BMRKR2")
    ),
    data = adtte_f,
    groups_lists = list(
        BMRKR2 = list(
            "low" = "LOW",
            "low/medium" = c("LOW", "MEDIUM"),
            "low/medium/high" = c("LOW", "MEDIUM", "HIGH")
        )
    )
)
df_grouped

## Table with default columns.
basic_table() %>%
    tabulate_survival_subgroups(df, time_unit = adtte_f$AVALU[1], 
                                label_all = "Full Analysis Set")

sessionInfo()

R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)

Matrix products: default

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

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

other attached packages:
[1] tern_0.9.4       rtables_0.6.7    magrittr_2.0.3   formatters_0.5.6 forcats_1.0.0    dplyr_1.1.4     

loaded via a namespace (and not attached):
 [1] pillar_1.9.0      compiler_4.2.2    tools_4.2.2       digest_0.6.35     lattice_0.22-6    lifecycle_1.0.4   tibble_3.2.1     
 [8] checkmate_2.3.1   gtable_0.3.4      pkgconfig_2.0.3   rlang_1.1.3       Matrix_1.6-5      cli_3.6.2         rstudioapi_0.16.0
[15] fastmap_1.1.1     generics_0.1.3    vctrs_0.6.5       grid_4.2.2        tidyselect_1.2.1  glue_1.7.0        R6_2.5.1         
[22] fansi_1.0.6       Rdpack_2.6        survival_3.5-8    ggplot2_3.5.0     purrr_1.0.2       tidyr_1.3.1       backports_1.4.1  
[29] scales_1.3.0      htmltools_0.5.8.1 rbibutils_2.2.16  splines_4.2.2     colorspace_2.1-0  utf8_1.2.4        stringi_1.8.3    
[36] munsell_0.5.1     broom_1.0.5

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.
@fenguoerbian fenguoerbian added the bug Something isn't working label Apr 19, 2024
@edelarua edelarua added the sme label Apr 19, 2024
@edelarua edelarua self-assigned this Apr 19, 2024
@edelarua
Copy link
Contributor

edelarua commented Apr 19, 2024

Hi @fenguoerbian,

Sorry for the confusion in the documentation (I'll update it accordingly), the label_all parameter should actuallly be assigned in the call(s) of extract_survival_subgroups. See the updated example below:

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

adtte <- tern_ex_adtte

# Save variable labels before data processing steps.
adtte_labels <- formatters::var_labels(adtte)

adtte_f <- adtte %>%
    filter(
        PARAMCD == "OS",
        ARM %in% c("B: Placebo", "A: Drug X"),
        SEX %in% c("M", "F")
    ) %>%
    mutate(
        # Reorder levels of ARM to display reference arm before treatment arm.
        ARM = droplevels(fct_relevel(ARM, "B: Placebo")),
        SEX = droplevels(SEX),
        AVALU = as.character(AVALU),
        is_event = CNSR == 0
    )
labels <- c(
    "ARM" = adtte_labels[["ARM"]],
    "SEX" = adtte_labels[["SEX"]],
    "AVALU" = adtte_labels[["AVALU"]],
    "is_event" = "Event Flag"
)
formatters::var_labels(adtte_f)[names(labels)] <- labels

df <- extract_survival_subgroups(
    variables = list(
        tte = "AVAL",
        is_event = "is_event",
        arm = "ARM", subgroups = c("SEX", "BMRKR2")
    ),
    data = adtte_f, 
    label_all = "Full Analysis Set"
)

df_grouped <- extract_survival_subgroups(
    variables = list(
        tte = "AVAL",
        is_event = "is_event",
        arm = "ARM", subgroups = c("SEX", "BMRKR2")
    ),
    data = adtte_f,
    groups_lists = list(
        BMRKR2 = list(
            "low" = "LOW",
            "low/medium" = c("LOW", "MEDIUM"),
            "low/medium/high" = c("LOW", "MEDIUM", "HIGH")
        )
    ), 
    label_all = "Full Analysis Set"
)

## Table with default columns.
basic_table() %>%
    tabulate_survival_subgroups(df, time_unit = adtte_f$AVALU[1])
#>                                                     B: Placebo               A: Drug X                                     
#> Baseline Risk Factors          Total Events   Events   Median (DAYS)   Events   Median (DAYS)   Hazard Ratio   95% Wald CI 
#> ———————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
#> Full Analysis Set                  101          57         727.8         44         974.6           0.71       (0.48, 1.06)
#> Sex                                                                                                                        
#>   F                                 55          31         599.2         24        1016.3           0.56       (0.32, 0.96)
#>   M                                 46          26         888.5         20         974.6           0.91       (0.50, 1.65)
#> Continuous Level Biomarker 2                                                                                               
#>   LOW                               36          21         735.5         15         974.6           0.76       (0.39, 1.51)
#>   MEDIUM                            31          14         731.8         17         964.2           0.77       (0.36, 1.61)
#>   HIGH                              34          22         654.8         12        1016.3           0.67       (0.33, 1.36)

Created on 2024-04-19 with reprex v2.1.0

@fenguoerbian
Copy link
Author

Thanks a lot!

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.

2 participants