h_survival_duration_subgroups | R Documentation |
Helper functions that tabulate in a data frame statistics such as median survival time and hazard ratio for population subgroups.
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"
)
tte |
( |
is_event |
( |
arm |
( |
variables |
(named |
data |
( |
groups_lists |
(named |
label_all |
( |
strata_data |
( |
control |
(
|
Main functionality is to prepare data for use in a layout-creating function.
h_survtime_df()
returns a data.frame
with columns arm
, n
, n_events
, and median
.
h_survtime_subgroups_df()
returns a data.frame
with columns arm
, n
, n_events
, median
, subgroup
,
var
, var_label
, and row_type
.
h_coxph_df()
returns a data.frame
with columns arm
, n_tot
, n_tot_events
, hr
, lcl
, ucl
,
conf_level
, pval
and pval_label
.
h_coxph_subgroups_df()
returns a data.frame
with columns arm
, n_tot
, n_tot_events
, hr
,
lcl
, ucl
, conf_level
, pval
, pval_label
, subgroup
, var
, var_label
, and row_type
.
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 in data
, passed as a named list and
requires elements tte
, is_event
, arm
and optionally subgroups
. groups_lists
optionally specifies
groupings for subgroups
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 in
data
, passed as a named list and requires elements tte
, is_event
, arm
and
optionally subgroups
and strata
. groups_lists
optionally specifies
groupings for subgroups
variables.
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
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.