Learn R Programming

tern (version 0.9.4)

summarize_change: Summarize the change from baseline or absolute baseline values

Description

[Stable]

The primary analysis variable .var indicates the numerical change from baseline results, and additional required secondary analysis variables are value and baseline_flag. Depending on the baseline flag, either the absolute baseline values (at baseline) or the change from baseline values (post-baseline) are then summarized.

Usage

summarize_change(
  lyt,
  vars,
  variables,
  na_str = default_na_str(),
  nested = TRUE,
  ...,
  table_names = vars,
  .stats = c("n", "mean_sd", "median", "range"),
  .formats = NULL,
  .labels = NULL,
  .indent_mods = NULL
)

s_change_from_baseline(df, .var, variables, na.rm = TRUE, ...)

a_change_from_baseline(df, .var, variables, na.rm = TRUE, ...)

Value

  • summarize_change() returns a layout object suitable for passing to further layouting functions, or to rtables::build_table(). Adding this function to an rtable layout will add formatted rows containing the statistics from s_change_from_baseline() to the table layout.

  • s_change_from_baseline() returns the same values returned by s_summary.numeric().

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

Arguments

lyt

(PreDataTableLayouts)
layout that analyses will be added to.

vars

(character)
variable names for the primary analysis variable to be iterated over.

variables

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

na_str

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

nested

(flag)
whether this layout instruction should be applied within the existing layout structure _if possible (TRUE, the default) or as a new top-level element (FALSE). Ignored if it would nest a split. underneath analyses, which is not allowed.

...

additional arguments for the lower level functions.

table_names

(character)
this can be customized in the case that the same vars are analyzed multiple times, to avoid warnings from rtables.

.stats

(character)
statistics to select for the table. Run get_stats("analyze_vars_numeric) to see available statistics for this function.

.formats

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

.labels

(named character)
labels for the statistics (without indent).

.indent_mods

(named integer)
indent modifiers for the labels. Defaults to 0, which corresponds to the unmodified default behavior. Can be negative.

df

(data.frame)
data set containing all analysis variables.

.var

(string)
single variable name that is passed by rtables when requested by a statistics function.

na.rm

(flag)
whether NA values should be removed from x prior to analysis.

Functions

  • summarize_change(): Layout-creating function which can take statistics function arguments and additional format arguments. This function is a wrapper for rtables::analyze().

  • s_change_from_baseline(): Statistics function that summarizes baseline or post-baseline visits.

  • a_change_from_baseline(): Formatted analysis function which is used as afun in summarize_change().

Examples

Run this code
library(dplyr)

## Fabricate dataset
dta_test <- data.frame(
  USUBJID = rep(1:6, each = 3),
  AVISIT = rep(paste0("V", 1:3), 6),
  ARM = rep(LETTERS[1:3], rep(6, 3)),
  AVAL = c(9:1, rep(NA, 9))
) %>%
  mutate(ABLFLL = AVISIT == "V1") %>%
  group_by(USUBJID) %>%
  mutate(
    BLVAL = AVAL[ABLFLL],
    CHG = AVAL - BLVAL
  ) %>%
  ungroup()

results <- basic_table() %>%
  split_cols_by("ARM") %>%
  split_rows_by("AVISIT") %>%
  summarize_change("CHG", variables = list(value = "AVAL", baseline_flag = "ABLFLL")) %>%
  build_table(dta_test)

results

Run the code above in your browser using DataLab