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

FDA Table 03

Subject Screening and Enrollment, Screening Population, Trials A and B

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

Code
# Load libraries & data -------------------------------------
library(dplyr)
library(formatters)
library(cards)
library(gtsummary)

adsl <- pharmaverseadam::adsl

set.seed(1)
adsl$RANDDT[sample(seq_len(nrow(adsl)), 100)] <- NA
scrnfail_reas_lvls <- c(
  "Inclusion/exclusion criteria not met", "Subject noncompliance", "Consent withdrawn", "Other"
)
data <- adsl |>
  mutate(
    ENRLDT = RANDDT,
    SCRNFL = with_label(TRUE, "Subjects screened"),
    SCRNFRS = factor(sample(scrnfail_reas_lvls, size = nrow(adsl), replace = TRUE),
      levels = scrnfail_reas_lvls
    ),
    ENRLFL = with_label(!is.na(ENRLDT), "Subjects enrolled"),
    RANDFL = with_label(!is.na(RANDDT), "Subjects randomized"),
    screen_fail = !ENRLFL # create a flag for screen failure
  )
data$SCRNFRS[data$SCRNFL == "N" | !is.na(data$ENRLDT)] <- NA
Code
tbl <- data |>
  tbl_summary(
    include = c(SCRNFL, screen_fail, SCRNFRS, ENRLFL, RANDFL),
    # suppress number of missing observations
    missing = "no",
    # specify the denominator is always the no. obs. in `data`
    percent = data,
    # present SCRNFRS in descending order of frequency
    sort = SCRNFRS ~ "frequency",
    # update default screen failure label
    label = list(screen_fail = "Screening failures")
  ) |>
  # remove the blank header row for SCRNFRS
  remove_row_type(SCRNFRS, type = "header") |>
  modify_header(
    label = "**Disposition**",
    stat_0 = "**Trial A**  \n N = {n}"
  ) |>
  # update indentation for screening failures subsection
  modify_indent(columns = label, rows = variable == "screen_fail", indent = 4L) |>
  modify_indent(columns = label, rows = variable == "SCRNFRS", indent = 8L)

tbl

Code
ard <- gather_ard(tbl)

ard
$tbl_summary
{cards} data frame: 61 x 10
   variable variable_level  context stat_name stat_label  stat
1   SCRNFRS      Inclusio… tabulate         n          n    40
2   SCRNFRS      Inclusio… tabulate         N          N   306
3   SCRNFRS      Inclusio… tabulate         p          % 0.131
4   SCRNFRS          Other tabulate         n          n    35
5   SCRNFRS          Other tabulate         N          N   306
6   SCRNFRS          Other tabulate         p          % 0.114
7   SCRNFRS      Consent … tabulate         n          n    33
8   SCRNFRS      Consent … tabulate         N          N   306
9   SCRNFRS      Consent … tabulate         p          % 0.108
10  SCRNFRS      Subject … tabulate         n          n    27
ℹ 51 more rows
ℹ Use `print(n = ...)` to see more rows
ℹ 4 more variables: fmt_fun, warning, error, gts_column
Source Code
---
title: FDA Table 03
subtitle: Subject Screening and Enrollment, Screening Population, Trials A and B
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(formatters)
library(cards)
library(gtsummary)

adsl <- pharmaverseadam::adsl

set.seed(1)
adsl$RANDDT[sample(seq_len(nrow(adsl)), 100)] <- NA
scrnfail_reas_lvls <- c(
  "Inclusion/exclusion criteria not met", "Subject noncompliance", "Consent withdrawn", "Other"
)
data <- adsl |>
  mutate(
    ENRLDT = RANDDT,
    SCRNFL = with_label(TRUE, "Subjects screened"),
    SCRNFRS = factor(sample(scrnfail_reas_lvls, size = nrow(adsl), replace = TRUE),
      levels = scrnfail_reas_lvls
    ),
    ENRLFL = with_label(!is.na(ENRLDT), "Subjects enrolled"),
    RANDFL = with_label(!is.na(RANDDT), "Subjects randomized"),
    screen_fail = !ENRLFL # create a flag for screen failure
  )
data$SCRNFRS[data$SCRNFL == "N" | !is.na(data$ENRLDT)] <- NA
```

## Build Table

```{r tbl, message=FALSE, warning=FALSE, results='hide'}
tbl <- data |>
  tbl_summary(
    include = c(SCRNFL, screen_fail, SCRNFRS, ENRLFL, RANDFL),
    # suppress number of missing observations
    missing = "no",
    # specify the denominator is always the no. obs. in `data`
    percent = data,
    # present SCRNFRS in descending order of frequency
    sort = SCRNFRS ~ "frequency",
    # update default screen failure label
    label = list(screen_fail = "Screening failures")
  ) |>
  # remove the blank header row for SCRNFRS
  remove_row_type(SCRNFRS, type = "header") |>
  modify_header(
    label = "**Disposition**",
    stat_0 = "**Trial A**  \n N = {n}"
  ) |>
  # update indentation for screening failures subsection
  modify_indent(columns = label, rows = variable == "screen_fail", indent = 4L) |>
  modify_indent(columns = label, rows = variable == "SCRNFRS", indent = 8L)

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 ARD
withr::local_options(width = 9999)
print(ard)
```
:::
 
  • This website as well as code examples are licensed under the Apache License, Version 2.0.
Cookie Preferences