h_survival_duration_subgroups {tern} | R Documentation |
Helper functions for tabulating survival duration by subgroup
Description
Helper functions that tabulate in a data frame statistics such as median survival time and hazard ratio for population subgroups.
Usage
h_survtime_df(tte, is_event, arm)
h_survtime_subgroups_df(
variables,
data,
groups_lists = list(),
label_all = "All Patients"
)
h_coxph_df(tte, is_event, arm, strata_data = NULL, control = control_coxph())
h_coxph_subgroups_df(
variables,
data,
groups_lists = list(),
control = control_coxph(),
label_all = "All Patients"
)
Arguments
tte |
( |
is_event |
( |
arm |
( |
variables |
(named |
data |
( |
groups_lists |
(named |
label_all |
( |
strata_data |
( |
control |
(
|
Details
Main functionality is to prepare data for use in a layout-creating function.
Value
-
h_survtime_df()
returns adata.frame
with columnsarm
,n
,n_events
, andmedian
.
-
h_survtime_subgroups_df()
returns adata.frame
with columnsarm
,n
,n_events
,median
,subgroup
,var
,var_label
, androw_type
.
-
h_coxph_df()
returns adata.frame
with columnsarm
,n_tot
,n_tot_events
,hr
,lcl
,ucl
,conf_level
,pval
andpval_label
.
-
h_coxph_subgroups_df()
returns adata.frame
with columnsarm
,n_tot
,n_tot_events
,hr
,lcl
,ucl
,conf_level
,pval
,pval_label
,subgroup
,var
,var_label
, androw_type
.
Functions
-
h_survtime_df()
: Helper to prepare a data frame of median survival times by arm. -
h_survtime_subgroups_df()
: Summarizes median survival times by arm and across subgroups in a data frame.variables
corresponds to the names of variables found indata
, passed as a named list and requires elementstte
,is_event
,arm
and optionallysubgroups
.groups_lists
optionally specifies groupings forsubgroups
variables. -
h_coxph_df()
: Helper to prepare a data frame with estimates of treatment hazard ratio. -
h_coxph_subgroups_df()
: Summarizes estimates of the treatment hazard ratio across subgroups in a data frame.variables
corresponds to the names of variables found indata
, passed as a named list and requires elementstte
,is_event
,arm
and optionallysubgroups
andstrata
.groups_lists
optionally specifies groupings forsubgroups
variables.
Examples
library(dplyr)
library(forcats)
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),
is_event = CNSR == 0
)
labels <- c("ARM" = adtte_labels[["ARM"]], "SEX" = adtte_labels[["SEX"]], "is_event" = "Event Flag")
formatters::var_labels(adtte_f)[names(labels)] <- labels
# Extract median survival time for one group.
h_survtime_df(
tte = adtte_f$AVAL,
is_event = adtte_f$is_event,
arm = adtte_f$ARM
)
# Extract median survival time for multiple groups.
h_survtime_subgroups_df(
variables = list(
tte = "AVAL",
is_event = "is_event",
arm = "ARM",
subgroups = c("SEX", "BMRKR2")
),
data = adtte_f
)
# Define groupings for BMRKR2 levels.
h_survtime_subgroups_df(
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")
)
)
)
# Extract hazard ratio for one group.
h_coxph_df(adtte_f$AVAL, adtte_f$is_event, adtte_f$ARM)
# Extract hazard ratio for one group with stratification factor.
h_coxph_df(adtte_f$AVAL, adtte_f$is_event, adtte_f$ARM, strata_data = adtte_f$STRATA1)
# Extract hazard ratio for multiple groups.
h_coxph_subgroups_df(
variables = list(
tte = "AVAL",
is_event = "is_event",
arm = "ARM",
subgroups = c("SEX", "BMRKR2")
),
data = adtte_f
)
# Define groupings of BMRKR2 levels.
h_coxph_subgroups_df(
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")
)
)
)
# Extract hazard ratio for multiple groups with stratification factors.
h_coxph_subgroups_df(
variables = list(
tte = "AVAL",
is_event = "is_event",
arm = "ARM",
subgroups = c("SEX", "BMRKR2"),
strata = c("STRATA1", "STRATA2")
),
data = adtte_f
)