Skip to contents

[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

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

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

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

Arguments

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.

variables

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

na.rm

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

...

additional arguments for the lower level functions.

lyt

(layout)
input layout where analyses will be added to.

vars

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

table_names

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

.stats

(character)
statistics to select for the table.

.formats

(named character or list)
formats for the statistics.

.labels

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

.indent_mods

(named integer)
indent modifiers for the labels.

Value

See s_summary.numeric() for the return values.

Functions

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

  • a_change_from_baseline(): Formatted Analysis function which can be further customized by calling rtables::make_afun() on it. It is used as afun in rtables::analyze().

  • summarize_change(): Analyze Function for change from baseline analysis. To be used after a split on visits in the layout, such that each data subset only contains either baseline or post-baseline data. Allows additional formatting options.

Note

The data in df must be either all be from baseline or post-baseline visits. Otherwise an error will be thrown.

Examples

df <- data.frame(
  chg = c(1, 2, 3),
  is_bl = c(TRUE, TRUE, TRUE),
  val = c(4, 5, 6)
)

# Internal function - s_change_from_baseline
if (FALSE) {
s_change_from_baseline(
  df,
  .var = "chg",
  variables = list(value = "val", baseline_flag = "is_bl")
)
}

# Internal function - a_change_from_baseline
if (FALSE) {
a_change_from_baseline(
  df,
  .var = "chg",
  variables = list(value = "val", baseline_flag = "is_bl")
)
}


# `summarize_change()`

## Fabricated dataset.
library(dplyr)

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)
if (FALSE) {
Viewer(results)
}