Usage
extract_rsp_subgroups(
variables,
data,
groups_lists = list(),
conf_level = 0.95,
method = NULL,
label_all = "All Patients"
)
a_response_subgroups(
.formats = list(n = "xx", n_rsp = "xx", prop = "xx.x%", n_tot = "xx", or =
list(format_extreme_values(2L)), ci = list(format_extreme_values_ci(2L)), pval =
"x.xxxx | (<0.0001)")
)
tabulate_rsp_subgroups(lyt, df, vars = c("n_tot", "n", "prop", "or", "ci"))
Arguments
- variables
(named
list
ofstring
)
list of additional analysis variables.- data
(
data frame
)
the dataset containing the variables to summarize.- groups_lists
(named
list
oflist
)
optionally contains for eachsubgroups
variable a list, which specifies the new group levels via the names and the levels that belong to it in the character vectors that are elements of the list.- conf_level
(
proportion
)
confidence level of the interval.- method
(
string
)
specifies the test used to calculate the p-value for the difference between two proportions. For options, sees_test_proportion_diff()
. Default isNULL
so no test is performed.- label_all
(
string
)
label for the total population analysis.- .formats
(named
character
orlist
)
formats for the statistics.- lyt
(
layout
)
input layout where analyses will be added to.- df
(
list
)
of data frames containing all analysis variables. List should be created usingextract_rsp_subgroups()
.- vars
(
character
)
the name of statistics to be reported amongn
(total number of observations per group),n_rsp
(number of responders per group),prop
(proportion of responders),n_tot
(total number of observations),or
(odds ratio),ci
(confidence interval of odds ratio) andpval
(p value of the effect). Note, the statisticsn_tot
,or
andci
are required.
Details
These functions create a layout starting from a data frame which contains the required statistics. Tables typically used as part of forest plot.
Functions
extract_rsp_subgroups()
: prepares response rates and odds ratios for population subgroups in data frames. Simple wrapper forh_odds_ratio_subgroups_df()
andh_proportion_subgroups_df()
. Result is a list of two data frames:prop
andor
.variables
corresponds to the names of variables found indata
, passed as a named list and requires elementsrsp
,arm
and optionallysubgroups
andstrat
.groups_lists
optionally specifies groupings forsubgroups
variables.a_response_subgroups()
: Formatted Analysis function used to format the results ofextract_rsp_subgroups()
. Returns is a list of Formatted Analysis functions with one element per statistic.tabulate_rsp_subgroups()
: table creating function.
Examples
# Testing dataset.
library(scda)
library(dplyr)
library(forcats)
library(rtables)
adrs <- synthetic_cdisc_data("latest")$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")
# Unstratified analysis.
df <- extract_rsp_subgroups(
variables = list(rsp = "rsp", arm = "ARM", subgroups = c("SEX", "BMRKR2")),
data = adrs_f
)
df
#> $prop
#> arm n n_rsp prop subgroup var
#> 1 B: Placebo 134 97 0.7238806 All Patients ALL
#> 2 A: Drug X 134 119 0.8880597 All Patients ALL
#> 3 B: Placebo 82 57 0.6951220 F SEX
#> 4 A: Drug X 79 73 0.9240506 F SEX
#> 5 B: Placebo 52 40 0.7692308 M SEX
#> 6 A: Drug X 55 46 0.8363636 M SEX
#> 7 B: Placebo 45 38 0.8444444 LOW BMRKR2
#> 8 A: Drug X 50 46 0.9200000 LOW BMRKR2
#> 9 B: Placebo 56 38 0.6785714 MEDIUM BMRKR2
#> 10 A: Drug X 37 31 0.8378378 MEDIUM BMRKR2
#> 11 B: Placebo 33 21 0.6363636 HIGH BMRKR2
#> 12 A: Drug X 47 42 0.8936170 HIGH BMRKR2
#> var_label row_type
#> 1 All Patients content
#> 2 All Patients content
#> 3 Sex analysis
#> 4 Sex analysis
#> 5 Sex analysis
#> 6 Sex analysis
#> 7 Categorical Level Biomarker 2 analysis
#> 8 Categorical Level Biomarker 2 analysis
#> 9 Categorical Level Biomarker 2 analysis
#> 10 Categorical Level Biomarker 2 analysis
#> 11 Categorical Level Biomarker 2 analysis
#> 12 Categorical Level Biomarker 2 analysis
#>
#> $or
#> arm n_tot or lcl ucl conf_level subgroup var
#> 1 268 3.026117 1.5685817 5.838002 0.95 All Patients ALL
#> 2 161 5.336257 2.0514242 13.880913 0.95 F SEX
#> 3 107 1.533333 0.5856092 4.014813 0.95 M SEX
#> 4 95 2.118421 0.5765066 7.784313 0.95 LOW BMRKR2
#> 5 93 2.447368 0.8662556 6.914371 0.95 MEDIUM BMRKR2
#> 6 80 4.800000 1.4936979 15.424806 0.95 HIGH BMRKR2
#> var_label row_type
#> 1 All Patients content
#> 2 Sex analysis
#> 3 Sex analysis
#> 4 Categorical Level Biomarker 2 analysis
#> 5 Categorical Level Biomarker 2 analysis
#> 6 Categorical Level Biomarker 2 analysis
#>
# Stratified analysis.
df_strat <- extract_rsp_subgroups(
variables = list(rsp = "rsp", arm = "ARM", subgroups = c("SEX", "BMRKR2"), strat = "STRATA1"),
data = adrs_f
)
df_strat
#> $prop
#> arm n n_rsp prop subgroup var
#> 1 B: Placebo 134 97 0.7238806 All Patients ALL
#> 2 A: Drug X 134 119 0.8880597 All Patients ALL
#> 3 B: Placebo 82 57 0.6951220 F SEX
#> 4 A: Drug X 79 73 0.9240506 F SEX
#> 5 B: Placebo 52 40 0.7692308 M SEX
#> 6 A: Drug X 55 46 0.8363636 M SEX
#> 7 B: Placebo 45 38 0.8444444 LOW BMRKR2
#> 8 A: Drug X 50 46 0.9200000 LOW BMRKR2
#> 9 B: Placebo 56 38 0.6785714 MEDIUM BMRKR2
#> 10 A: Drug X 37 31 0.8378378 MEDIUM BMRKR2
#> 11 B: Placebo 33 21 0.6363636 HIGH BMRKR2
#> 12 A: Drug X 47 42 0.8936170 HIGH BMRKR2
#> var_label row_type
#> 1 All Patients content
#> 2 All Patients content
#> 3 Sex analysis
#> 4 Sex analysis
#> 5 Sex analysis
#> 6 Sex analysis
#> 7 Categorical Level Biomarker 2 analysis
#> 8 Categorical Level Biomarker 2 analysis
#> 9 Categorical Level Biomarker 2 analysis
#> 10 Categorical Level Biomarker 2 analysis
#> 11 Categorical Level Biomarker 2 analysis
#> 12 Categorical Level Biomarker 2 analysis
#>
#> $or
#> arm n_tot or lcl ucl conf_level subgroup var
#> 1 268 3.036189 1.5749483 5.853173 0.95 All Patients ALL
#> 2 161 5.211620 2.0113615 13.503781 0.95 F SEX
#> 3 107 1.628393 0.6196333 4.279406 0.95 M SEX
#> 4 95 2.045340 0.5597227 7.474085 0.95 LOW BMRKR2
#> 5 93 2.423656 0.8624779 6.810734 0.95 MEDIUM BMRKR2
#> 6 80 4.540487 1.4443496 14.273571 0.95 HIGH BMRKR2
#> var_label row_type
#> 1 All Patients content
#> 2 Sex analysis
#> 3 Sex analysis
#> 4 Categorical Level Biomarker 2 analysis
#> 5 Categorical Level Biomarker 2 analysis
#> 6 Categorical Level Biomarker 2 analysis
#>
# Grouping of the BMRKR2 levels.
df_grouped <- extract_rsp_subgroups(
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")
)
)
)
df_grouped
#> $prop
#> arm n n_rsp prop subgroup var
#> 1 B: Placebo 134 97 0.7238806 All Patients ALL
#> 2 A: Drug X 134 119 0.8880597 All Patients ALL
#> 3 B: Placebo 82 57 0.6951220 F SEX
#> 4 A: Drug X 79 73 0.9240506 F SEX
#> 5 B: Placebo 52 40 0.7692308 M SEX
#> 6 A: Drug X 55 46 0.8363636 M SEX
#> 7 B: Placebo 45 38 0.8444444 low BMRKR2
#> 8 A: Drug X 50 46 0.9200000 low BMRKR2
#> 9 B: Placebo 101 76 0.7524752 low/medium BMRKR2
#> 10 A: Drug X 87 77 0.8850575 low/medium BMRKR2
#> 11 B: Placebo 134 97 0.7238806 low/medium/high BMRKR2
#> 12 A: Drug X 134 119 0.8880597 low/medium/high BMRKR2
#> var_label row_type
#> 1 All Patients content
#> 2 All Patients content
#> 3 Sex analysis
#> 4 Sex analysis
#> 5 Sex analysis
#> 6 Sex analysis
#> 7 Categorical Level Biomarker 2 analysis
#> 8 Categorical Level Biomarker 2 analysis
#> 9 Categorical Level Biomarker 2 analysis
#> 10 Categorical Level Biomarker 2 analysis
#> 11 Categorical Level Biomarker 2 analysis
#> 12 Categorical Level Biomarker 2 analysis
#>
#> $or
#> arm n_tot or lcl ucl conf_level subgroup var
#> 1 268 3.026117 1.5685817 5.838002 0.95 All Patients ALL
#> 2 161 5.336257 2.0514242 13.880913 0.95 F SEX
#> 3 107 1.533333 0.5856092 4.014813 0.95 M SEX
#> 4 95 2.118421 0.5765066 7.784313 0.95 low BMRKR2
#> 5 188 2.532895 1.1393669 5.630807 0.95 low/medium BMRKR2
#> 6 268 3.026117 1.5685817 5.838002 0.95 low/medium/high BMRKR2
#> var_label row_type
#> 1 All Patients content
#> 2 Sex analysis
#> 3 Sex analysis
#> 4 Categorical Level Biomarker 2 analysis
#> 5 Categorical Level Biomarker 2 analysis
#> 6 Categorical Level Biomarker 2 analysis
#>
# Internal function - a_response_subgroups
if (FALSE) {
a_response_subgroups(.formats = list("n" = "xx", "prop" = "xx.xx%"))
}
## Table with default columns.
basic_table() %>%
tabulate_rsp_subgroups(df)
#> Baseline Risk Factors B: Placebo A: Drug X
#> Total n n Response (%) n Response (%) Odds Ratio 95% CI
#> ——————————————————————————————————————————————————————————————————————————————————————————————————————————————
#> All Patients 268 134 72.4% 134 88.8% 3.03 (1.57, 5.84)
#> Sex
#> F 161 82 69.5% 79 92.4% 5.34 (2.05, 13.88)
#> M 107 52 76.9% 55 83.6% 1.53 (0.59, 4.01)
#> Categorical Level Biomarker 2
#> LOW 95 45 84.4% 50 92.0% 2.12 (0.58, 7.78)
#> MEDIUM 93 56 67.9% 37 83.8% 2.45 (0.87, 6.91)
#> HIGH 80 33 63.6% 47 89.4% 4.80 (1.49, 15.42)
## Table with selected columns.
basic_table() %>%
tabulate_rsp_subgroups(
df = df,
vars = c("n_tot", "n", "n_rsp", "prop", "or", "ci")
)
#> Baseline Risk Factors B: Placebo A: Drug X
#> Total n n Responders Response (%) n Responders Response (%) Odds Ratio 95% CI
#> ————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
#> All Patients 268 134 97 72.4% 134 119 88.8% 3.03 (1.57, 5.84)
#> Sex
#> F 161 82 57 69.5% 79 73 92.4% 5.34 (2.05, 13.88)
#> M 107 52 40 76.9% 55 46 83.6% 1.53 (0.59, 4.01)
#> Categorical Level Biomarker 2
#> LOW 95 45 38 84.4% 50 46 92.0% 2.12 (0.58, 7.78)
#> MEDIUM 93 56 38 67.9% 37 31 83.8% 2.45 (0.87, 6.91)
#> HIGH 80 33 21 63.6% 47 42 89.4% 4.80 (1.49, 15.42)