Skip to contents

[Stable]

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

(logical)
whether each subject is a responder or not.

arm

(factor)
the treatment group variable.

variables

(named list of string)
list of additional analysis variables.

data

(data.frame)
the dataset containing the variables to summarize.

groups_lists

(named list of list)
optionally contains for each subgroups 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.

label_all

(string)
label for the total population analysis.

strata_data

(factor, data.frame or NULL)
required if stratified analysis is performed.

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, see s_test_proportion_diff(). Default is NULL so no test is performed.

Details

Helper functions that tabulate in a data frame statistics such as response rate and odds ratio for population subgroups.

Main functionality is to prepare data for use in a layout creating function.

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 in data, passed as a named list and requires elements rsp, arm and optionally subgroups. groups_lists optionally specifies groupings for subgroups 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 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.

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")

h_proportion_df(
  c(TRUE, FALSE, FALSE),
  arm = factor(c("A", "A", "B"), levels = c("A", "B"))
)
#>   arm n n_rsp prop
#> 1   A 2     1  0.5
#> 2   B 1     0  0.0

h_proportion_subgroups_df(
  variables = list(rsp = "rsp", arm = "ARM", subgroups = c("SEX", "BMRKR2")),
  data = adrs_f
)
#>           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

# 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")
    )
  )
)
#>           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

# Unstratatified analysis.
h_odds_ratio_df(
  c(TRUE, FALSE, FALSE, TRUE),
  arm = factor(c("A", "A", "B", "B"), levels = c("A", "B"))
)
#>   arm n_tot or        lcl      ucl conf_level
#> 1         4  1 0.01984252 50.39681       0.95

# Include p-value.
h_odds_ratio_df(adrs_f$rsp, adrs_f$ARM, method = "chisq")
#>   arm n_tot       or      lcl      ucl conf_level         pval
#> 1       268 3.026117 1.568582 5.838002       0.95 0.0006780638
#>                   pval_label
#> 1 p-value (Chi-Squared Test)

# Stratatified analysis.
h_odds_ratio_df(
  rsp = adrs_f$rsp,
  arm = adrs_f$ARM,
  strata_data = adrs_f[, c("STRATA1", "STRATA2")],
  method = "cmh"
)
#>   arm n_tot       or      lcl      ucl conf_level         pval
#> 1       268 3.005846 1.557529 5.800926       0.95 0.0007333883
#>                               pval_label
#> 1 p-value (Cochran-Mantel-Haenszel Test)

# Unstratified analysis.
h_odds_ratio_subgroups_df(
  variables = list(rsp = "rsp", arm = "ARM", subgroups = c("SEX", "BMRKR2")),
  data = adrs_f
)
#>   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.
h_odds_ratio_subgroups_df(
  variables = list(
    rsp = "rsp",
    arm = "ARM",
    subgroups = c("SEX", "BMRKR2"),
    strat = c("STRATA1", "STRATA2")
  ),
  data = adrs_f
)
#>   arm n_tot       or       lcl       ucl conf_level     subgroup    var
#> 1       268 3.005846 1.5575292  5.800926       0.95 All Patients    ALL
#> 2       161 5.103854 1.9778623 13.170445       0.95            F    SEX
#> 3       107 1.650601 0.6196854  4.396560       0.95            M    SEX
#> 4        95 2.216688 0.6016764  8.166691       0.95          LOW BMRKR2
#> 5        93 2.426440 0.8656775  6.801158       0.95       MEDIUM BMRKR2
#> 6        80 4.154569 1.3387881 12.892586       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

# 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")
    )
  )
)
#>   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