response_subgroups: Tabulate binary response by subgroup

response_subgroupsR Documentation

Tabulate binary response by subgroup

Description

[Stable]

Tabulate statistics such as response rate and odds ratio for population subgroups.

Usage

tabulate_rsp_subgroups(
  lyt,
  df,
  vars = c("n_tot", "n", "prop", "or", "ci"),
  groups_lists = list(),
  label_all = "All Patients",
  na_str = default_na_str()
)

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)"),
  na_str = default_na_str()
)

Arguments

lyt

(PreDataTableLayouts)
layout that analyses will be added to.

df

(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.

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


tern documentation built on June 22, 2024, 10:25 a.m.