cardinal
  • Home
  • Template Catalog
  • About
  • Resources
  • Help
    • Getting Started
    • Report a Bug
    • FAQ

FDA Table 04

Subject Populations, Randomized Population, Pooled Analysis (or Trial X)

table
FDA
safety
disposition
  • Table Preview
  • Setup
  • Build Table
  • Build ARD

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

Code
ard <- gather_ard(tbl)
ard
$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
Source Code
---
title: FDA Table 04
subtitle: Subject Populations, Randomized Population, Pooled Analysis (or Trial X) 
categories: [table, FDA, safety, disposition]
---

::: panel-tabset
## Table Preview

```{r img, echo=FALSE, fig.align='center', out.width='60%'}
knitr::include_graphics("result.png")
```

## Setup

```{r setup, message=FALSE}
# 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)
  )
```

## Build Table

```{r tbl, results='hide'}
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
```

```{r eval=FALSE, include=FALSE}
# Run chunk locally to generate image file
gt::gtsave(as_gt(tbl), filename = "result.png")
```

```{r img, echo=FALSE, fig.align='center', out.width='60%'}
```

## Build ARD

```{r ard, message=FALSE, warning=FALSE, results='hide'}
ard <- gather_ard(tbl)
ard
```

```{r, echo=FALSE}
# Print full ARD
withr::local_options(width = 9999)
print(ard, columns = "all")
```
:::
 
  • This website as well as code examples are licensed under the Apache License, Version 2.0.
Cookie Preferences