Code Monkey home page Code Monkey logo

Comments (2)

edelarua avatar edelarua commented on September 26, 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

from tern.

fenguoerbian avatar fenguoerbian commented on September 26, 2024

Thanks a lot!

from tern.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.