response_subgroups: Tabulate binary response by subgroup

response_subgroupsR Documentation

Tabulate binary response by subgroup

Description

[Stable]

The tabulate_rsp_subgroups() function creates a layout element to tabulate binary response by subgroup, returning statistics including response rate and odds ratio for each population subgroup. The table is created from df, a list of data frames returned by extract_rsp_subgroups(), with the statistics to include specified via the vars parameter.

A forest plot can be created from the resulting table using the g_forest() function.

Usage

tabulate_rsp_subgroups(
  lyt,
  df,
  vars = c("n_tot", "n", "prop", "or", "ci"),
  groups_lists = list(),
  label_all = "All Patients",
  riskdiff = NULL,
  na_str = default_na_str(),
  .formats = c(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)")
)

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)", riskdiff = "xx.x (xx.x - xx.x)"),
  na_str = default_na_str()
)

Arguments

lyt

(PreDataTableLayouts)
layout that analyses will be added to.

df

(list)
a list of data frames containing all analysis variables. List should be created using extract_rsp_subgroups().

vars

(character)
the names of statistics to be reported among:

  • n: 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.

  • pval: p-value of the effect. Note, the statistics n_tot, or, and ci are required.

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.

riskdiff

(list)
if a risk (proportion) difference column should be added, a list of settings to apply within the column. See control_riskdiff() for details. If NULL, no risk difference column will be added. If riskdiff$arm_x and riskdiff$arm_y are NULL, the first level of df$prop$arm will be used as arm_x and the second level as arm_y.

na_str

(string)
string used to replace all NA or empty values in the output.

.formats

(named character or list)
formats for the statistics. See Details in analyze_vars for more information on the "auto" setting.

Details

These functions create a layout starting from a data frame which contains the required statistics. Tables typically used as part of forest plot.

Value

An rtables table summarizing binary response by subgroup.

  • a_response_subgroups() returns the corresponding list with formatted rtables::CellValue().

Functions

  • tabulate_rsp_subgroups(): Table-creating function which creates a table summarizing binary response by subgroup. This function is a wrapper for rtables::analyze_colvars() and rtables::summarize_row_groups().

  • a_response_subgroups(): Formatted analysis function which is used as afun in tabulate_rsp_subgroups().

See Also

extract_rsp_subgroups()

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

# Stratified analysis.
df_strat <- extract_rsp_subgroups(
  variables = list(rsp = "rsp", arm = "ARM", subgroups = c("SEX", "BMRKR2"), strata = "STRATA1"),
  data = adrs_f
)
df_strat

# 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

# Table with default columns
basic_table() %>%
  tabulate_rsp_subgroups(df)

# Table with selected columns
basic_table() %>%
  tabulate_rsp_subgroups(
    df = df,
    vars = c("n_tot", "n", "n_rsp", "prop", "or", "ci")
  )

# Table with risk difference column added
basic_table() %>%
  tabulate_rsp_subgroups(
    df,
    riskdiff = control_riskdiff(
      arm_x = levels(df$prop$arm)[1],
      arm_y = levels(df$prop$arm)[2]
    )
  )


tern documentation built on Sept. 24, 2024, 9:06 a.m.