h_response_subgroups {tern} | R Documentation |
Helper functions for tabulating binary response by subgroup
Description
Helper functions that tabulate in a data frame statistics such as response rate and odds ratio for population subgroups.
Usage
h_proportion_df(rsp, arm)
h_proportion_subgroups_df(
variables,
data,
groups_lists = list(),
label_all = "All Patients"
)
h_odds_ratio_df(rsp, arm, strata_data = NULL, conf_level = 0.95, method = NULL)
h_odds_ratio_subgroups_df(
variables,
data,
groups_lists = list(),
conf_level = 0.95,
method = NULL,
label_all = "All Patients"
)
Arguments
rsp |
( |
arm |
( |
variables |
(named |
data |
( |
groups_lists |
(named |
label_all |
( |
strata_data |
( |
conf_level |
( |
method |
( |
Details
Main functionality is to prepare data for use in a layout-creating function.
Value
-
h_proportion_df()
returns adata.frame
with columnsarm
,n
,n_rsp
, andprop
.
-
h_proportion_subgroups_df()
returns adata.frame
with columnsarm
,n
,n_rsp
,prop
,subgroup
,var
,var_label
, androw_type
.
-
h_odds_ratio_df()
returns adata.frame
with columnsarm
,n_tot
,or
,lcl
,ucl
,conf_level
, and optionallypval
andpval_label
.
-
h_odds_ratio_subgroups_df()
returns adata.frame
with columnsarm
,n_tot
,or
,lcl
,ucl
,conf_level
,subgroup
,var
,var_label
, androw_type
.
Functions
-
h_proportion_df()
: Helper to prepare a data frame of binary responses by arm. -
h_proportion_subgroups_df()
: Summarizes proportion of binary responses 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 elementsrsp
,arm
and optionallysubgroups
.groups_lists
optionally specifies groupings forsubgroups
variables. -
h_odds_ratio_df()
: Helper to prepare a data frame with estimates of the odds ratio between a treatment and a control arm. -
h_odds_ratio_subgroups_df()
: Summarizes estimates of the odds ratio between a treatment and a control arm across subgroups in a data frame.variables
corresponds to the names of variables found indata
, passed as a named list and requires elementsrsp
,arm
and optionallysubgroups
andstrata
.groups_lists
optionally specifies groupings forsubgroups
variables.
Examples
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")
h_proportion_df(
c(TRUE, FALSE, FALSE),
arm = factor(c("A", "A", "B"), levels = c("A", "B"))
)
h_proportion_subgroups_df(
variables = list(rsp = "rsp", arm = "ARM", subgroups = c("SEX", "BMRKR2")),
data = adrs_f
)
# Define groupings for BMRKR2 levels.
h_proportion_subgroups_df(
variables = list(rsp = "rsp", arm = "ARM", subgroups = c("SEX", "BMRKR2")),
data = adrs_f,
groups_lists = list(
BMRKR2 = list(
"low" = "LOW",
"low/medium" = c("LOW", "MEDIUM"),
"low/medium/high" = c("LOW", "MEDIUM", "HIGH")
)
)
)
# Unstratatified analysis.
h_odds_ratio_df(
c(TRUE, FALSE, FALSE, TRUE),
arm = factor(c("A", "A", "B", "B"), levels = c("A", "B"))
)
# Include p-value.
h_odds_ratio_df(adrs_f$rsp, adrs_f$ARM, method = "chisq")
# Stratatified analysis.
h_odds_ratio_df(
rsp = adrs_f$rsp,
arm = adrs_f$ARM,
strata_data = adrs_f[, c("STRATA1", "STRATA2")],
method = "cmh"
)
# Unstratified analysis.
h_odds_ratio_subgroups_df(
variables = list(rsp = "rsp", arm = "ARM", subgroups = c("SEX", "BMRKR2")),
data = adrs_f
)
# Stratified analysis.
h_odds_ratio_subgroups_df(
variables = list(
rsp = "rsp",
arm = "ARM",
subgroups = c("SEX", "BMRKR2"),
strata = c("STRATA1", "STRATA2")
),
data = adrs_f
)
# Define groupings of BMRKR2 levels.
h_odds_ratio_subgroups_df(
variables = list(
rsp = "rsp",
arm = "ARM",
subgroups = c("SEX", "BMRKR2")
),
data = adrs_f,
groups_lists = list(
BMRKR2 = list(
"low" = "LOW",
"low/medium" = c("LOW", "MEDIUM"),
"low/medium/high" = c("LOW", "MEDIUM", "HIGH")
)
)
)