FDA Table 04
Subject Populations, Randomized Population, Pooled Analysis (or Trial X)
table
FDA
safety
disposition
Code
# Load libraries & data -------------------------------------
library(dplyr)
library(gtsummary)
library(formatters)
adsl <- random.cdisc.data::cadsl
# Pre-processing --------------------------------------------
pop_vars <- c("rand_fl", "ITTFL", "SAFFL", "prot_fl")
lbl_pop_vars <- c("Subjects randomized", "ITT population", "Safety population", "Per-protocol population")
data <- adsl |>
mutate(
across(all_of(c("ITTFL", "SAFFL")), ~ with_label(. == "Y", lbl_pop_vars[match(cur_column(), pop_vars)])),
rand_fl = !is.na(RANDDT),
prot_fl = is.na(DCSREAS)
)
Code
tbl <- data |>
tbl_summary(
by = "TRT01A",
statistic = list(all_dichotomous() ~ "{n} ({p}%)"),
include = all_of(pop_vars),
digits = list(all_categorical() ~ c(0, 1)),
label = as.list(lbl_pop_vars) |> setNames(pop_vars)
) |>
# Define which variables are children of parent variables
modify_indent(
columns = "label",
rows = variable != "rand_fl",
indent = 4L
) |>
modify_header(label = "**Population**")
tbl
$tbl_summary
{cards} data frame: 117 x 12
group1 group1_level variable variable_level context stat_name stat_label stat fmt_fun warning error gts_column
1 TRT01A A: Drug X ITTFL TRUE tabulate… n n 134 <fn> stat_1
2 TRT01A A: Drug X ITTFL TRUE tabulate… N N 134 0 stat_1
3 TRT01A A: Drug X ITTFL TRUE tabulate… p % 1 <fn> stat_1
4 TRT01A A: Drug X SAFFL TRUE tabulate… n n 134 <fn> stat_1
5 TRT01A A: Drug X SAFFL TRUE tabulate… N N 134 0 stat_1
6 TRT01A A: Drug X SAFFL TRUE tabulate… p % 1 <fn> stat_1
7 TRT01A A: Drug X rand_fl TRUE tabulate… n n 134 <fn> stat_1
8 TRT01A A: Drug X rand_fl TRUE tabulate… N N 134 0 stat_1
9 TRT01A A: Drug X rand_fl TRUE tabulate… p % 1 <fn> stat_1
10 TRT01A A: Drug X prot_fl TRUE tabulate… n n 92 <fn> stat_1
ℹ 107 more rows
ℹ Use `print(n = ...)` to see more rows