Prepares Response Data for Population Subgroups in Data Frames
Source:R/response_subgroups.R
extract_rsp_subgroups.Rd
Prepares response rates and odds ratios for population subgroups in data frames. Simple wrapper
for h_odds_ratio_subgroups_df()
and h_proportion_subgroups_df()
. Result is a list of two
data.frames
: prop
and or
. variables
corresponds to the names of variables found in data
,
passed as a named list
and requires elements rsp
, arm
and optionally subgroups
and strat
.
groups_lists
optionally specifies groupings for subgroups
variables.
Usage
extract_rsp_subgroups(
variables,
data,
groups_lists = list(),
conf_level = 0.95,
method = NULL,
label_all = "All Patients"
)
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.
Value
A named list of two elements:
prop
: Adata.frame
containing columnsarm
,n
,n_rsp
,prop
,subgroup
,var
,var_label
, androw_type
.or
: Adata.frame
containing columnsarm
,n_tot
,or
,lcl
,ucl
,conf_level
,subgroup
,var
,var_label
, androw_type
.
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")
# 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 73 50 0.6849315 All Patients ALL
#> 2 A: Drug X 69 59 0.8550725 All Patients ALL
#> 3 B: Placebo 40 25 0.6250000 F SEX
#> 4 A: Drug X 38 36 0.9473684 F SEX
#> 5 B: Placebo 33 25 0.7575758 M SEX
#> 6 A: Drug X 31 23 0.7419355 M SEX
#> 7 B: Placebo 24 13 0.5416667 LOW BMRKR2
#> 8 A: Drug X 26 21 0.8076923 LOW BMRKR2
#> 9 B: Placebo 23 17 0.7391304 MEDIUM BMRKR2
#> 10 A: Drug X 26 23 0.8846154 MEDIUM BMRKR2
#> 11 B: Placebo 26 20 0.7692308 HIGH BMRKR2
#> 12 A: Drug X 17 15 0.8823529 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 Continuous Level Biomarker 2 analysis
#> 8 Continuous Level Biomarker 2 analysis
#> 9 Continuous Level Biomarker 2 analysis
#> 10 Continuous Level Biomarker 2 analysis
#> 11 Continuous Level Biomarker 2 analysis
#> 12 Continuous Level Biomarker 2 analysis
#>
#> $or
#> arm n_tot or lcl ucl conf_level subgroup var
#> 1 142 2.714000 1.1804488 6.239827 0.95 All Patients ALL
#> 2 78 10.800000 2.2669576 51.452218 0.95 F SEX
#> 3 64 0.920000 0.2966470 2.853223 0.95 M SEX
#> 4 50 3.553846 1.0047370 12.570277 0.95 LOW BMRKR2
#> 5 49 2.705882 0.5911718 12.385232 0.95 MEDIUM BMRKR2
#> 6 43 2.250000 0.3970298 12.750933 0.95 HIGH BMRKR2
#> var_label row_type
#> 1 All Patients content
#> 2 Sex analysis
#> 3 Sex analysis
#> 4 Continuous Level Biomarker 2 analysis
#> 5 Continuous Level Biomarker 2 analysis
#> 6 Continuous 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 73 50 0.6849315 All Patients ALL
#> 2 A: Drug X 69 59 0.8550725 All Patients ALL
#> 3 B: Placebo 40 25 0.6250000 F SEX
#> 4 A: Drug X 38 36 0.9473684 F SEX
#> 5 B: Placebo 33 25 0.7575758 M SEX
#> 6 A: Drug X 31 23 0.7419355 M SEX
#> 7 B: Placebo 24 13 0.5416667 LOW BMRKR2
#> 8 A: Drug X 26 21 0.8076923 LOW BMRKR2
#> 9 B: Placebo 23 17 0.7391304 MEDIUM BMRKR2
#> 10 A: Drug X 26 23 0.8846154 MEDIUM BMRKR2
#> 11 B: Placebo 26 20 0.7692308 HIGH BMRKR2
#> 12 A: Drug X 17 15 0.8823529 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 Continuous Level Biomarker 2 analysis
#> 8 Continuous Level Biomarker 2 analysis
#> 9 Continuous Level Biomarker 2 analysis
#> 10 Continuous Level Biomarker 2 analysis
#> 11 Continuous Level Biomarker 2 analysis
#> 12 Continuous Level Biomarker 2 analysis
#>
#> $or
#> arm n_tot or lcl ucl conf_level subgroup var
#> 1 142 2.6343899 1.1537821 6.015009 0.95 All Patients ALL
#> 2 78 9.5946605 2.0379337 45.171985 0.95 F SEX
#> 3 64 0.8947158 0.2936803 2.725809 0.95 M SEX
#> 4 50 3.5976656 1.0101319 12.813374 0.95 LOW BMRKR2
#> 5 49 2.6242168 0.5162572 13.339308 0.95 MEDIUM BMRKR2
#> 6 43 2.2816865 0.4116391 12.647228 0.95 HIGH BMRKR2
#> var_label row_type
#> 1 All Patients content
#> 2 Sex analysis
#> 3 Sex analysis
#> 4 Continuous Level Biomarker 2 analysis
#> 5 Continuous Level Biomarker 2 analysis
#> 6 Continuous 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 73 50 0.6849315 All Patients ALL
#> 2 A: Drug X 69 59 0.8550725 All Patients ALL
#> 3 B: Placebo 40 25 0.6250000 F SEX
#> 4 A: Drug X 38 36 0.9473684 F SEX
#> 5 B: Placebo 33 25 0.7575758 M SEX
#> 6 A: Drug X 31 23 0.7419355 M SEX
#> 7 B: Placebo 24 13 0.5416667 low BMRKR2
#> 8 A: Drug X 26 21 0.8076923 low BMRKR2
#> 9 B: Placebo 47 30 0.6382979 low/medium BMRKR2
#> 10 A: Drug X 52 44 0.8461538 low/medium BMRKR2
#> 11 B: Placebo 73 50 0.6849315 low/medium/high BMRKR2
#> 12 A: Drug X 69 59 0.8550725 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 Continuous Level Biomarker 2 analysis
#> 8 Continuous Level Biomarker 2 analysis
#> 9 Continuous Level Biomarker 2 analysis
#> 10 Continuous Level Biomarker 2 analysis
#> 11 Continuous Level Biomarker 2 analysis
#> 12 Continuous Level Biomarker 2 analysis
#>
#> $or
#> arm n_tot or lcl ucl conf_level subgroup var
#> 1 142 2.714000 1.180449 6.239827 0.95 All Patients ALL
#> 2 78 10.800000 2.266958 51.452218 0.95 F SEX
#> 3 64 0.920000 0.296647 2.853223 0.95 M SEX
#> 4 50 3.553846 1.004737 12.570277 0.95 low BMRKR2
#> 5 99 3.116667 1.193409 8.139385 0.95 low/medium BMRKR2
#> 6 142 2.714000 1.180449 6.239827 0.95 low/medium/high BMRKR2
#> var_label row_type
#> 1 All Patients content
#> 2 Sex analysis
#> 3 Sex analysis
#> 4 Continuous Level Biomarker 2 analysis
#> 5 Continuous Level Biomarker 2 analysis
#> 6 Continuous Level Biomarker 2 analysis
#>