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

FDA Table 3

Patient Screening and Enrollment, Trials A and B

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

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

adsl <- random.cdisc.data::cadsl

set.seed(1)
adsl$RANDDT[sample(seq_len(nrow(adsl)), 100)] <- NA
scrnfail_reas_lvls <- c(
  "Inclusion/exclusion criteria not met", "Patient noncompliance", "Consent withdrawn", "Other"
)
data <- adsl |>
  mutate(
    ENRLDT = RANDDT,
    SCRNFL = with_label(TRUE, "Patients screened"),
    SCRNFRS = factor(sample(scrnfail_reas_lvls, size = nrow(adsl), replace = TRUE),
      levels = scrnfail_reas_lvls
    ),
    ENRLFL = with_label(!is.na(ENRLDT), "Patients enrolled"),
    RANDFL = with_label(!is.na(RANDDT), "Patients randomized")
  )
data$SCRNFRS[data$SCRNFL == "N" | !is.na(data$ENRLDT)] <- NA
Code
ard <- data |>
  ard_stack(
    ard_dichotomous(
      variables = SCRNFL,
      value = list(SCRNFL = TRUE),
      statistic = everything() ~ c("n")
    ),
    ard_categorical(
      variables = SCRNFRS,
      statistic = everything() ~ c("n", "p"),
      denominator = data
    ),
    ard_dichotomous(
      variables = c(ENRLFL, RANDFL),
      value = list(ENRLFL = TRUE, RANDFL = TRUE),
      statistic = everything() ~ c("n", "p"),
      denominator = data
    )
  )

ard
{cards} data frame: 13 x 9
   variable variable_level   context stat_name stat_label  stat fmt_fun warning error
1    SCRNFL           TRUE dichotom…         n          n   400       0              
2   SCRNFRS      Inclusio… categori…         n          n    26       0              
3   SCRNFRS      Inclusio… categori…         p          % 0.065    <fn>              
4   SCRNFRS      Patient … categori…         n          n    20       0              
5   SCRNFRS      Patient … categori…         p          %  0.05    <fn>              
6   SCRNFRS      Consent … categori…         n          n    30       0              
7   SCRNFRS      Consent … categori…         p          % 0.075    <fn>              
8   SCRNFRS          Other categori…         n          n    24       0              
9   SCRNFRS          Other categori…         p          %  0.06    <fn>              
10   ENRLFL           TRUE dichotom…         n          n   300       0              
11   ENRLFL           TRUE dichotom…         p          %  0.75    <fn>              
12   RANDFL           TRUE dichotom…         n          n   300       0              
13   RANDFL           TRUE dichotom…         p          %  0.75    <fn>              
Code
tbl_scrn <- tbl_summary(
  data = data,
  include = "SCRNFL",
  statistic = SCRNFL ~ "{n}",
  missing = "no"
)

tbl_scrnfrs <- tbl_hierarchical(
  data = data,
  denominator = adsl,
  id = USUBJID,
  variables = "SCRNFRS",
  statistic = ~"{n} ({p}%)",
  label = list(..ard_hierarchical_overall.. = "Screening failures"),
  overall_row = TRUE
)

tbl_enrl_rand <- tbl_summary(
  data = data,
  include = c("ENRLFL", "RANDFL"),
  missing = "no"
)

tbl <- list(tbl_scrn, tbl_scrnfrs, tbl_enrl_rand) |>
  tbl_stack() |>
  modify_header(label = "**Disposition**", stat_0 = "**Trial A**") |>
  modify_column_indent("label", rows = !(variable %in% c("..ard_hierarchical_overall..", "SCRNFL", "ENRLFL", "RANDFL"))) |>
  remove_footnote_header(columns = everything())

tbl

Source Code
---
title: FDA Table 3
subtitle: Patient Screening and Enrollment, 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 <- random.cdisc.data::cadsl

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

## Build ARD

```{r ard, message=FALSE, warning=FALSE, results='hide'}
ard <- data |>
  ard_stack(
    ard_dichotomous(
      variables = SCRNFL,
      value = list(SCRNFL = TRUE),
      statistic = everything() ~ c("n")
    ),
    ard_categorical(
      variables = SCRNFRS,
      statistic = everything() ~ c("n", "p"),
      denominator = data
    ),
    ard_dichotomous(
      variables = c(ENRLFL, RANDFL),
      value = list(ENRLFL = TRUE, RANDFL = TRUE),
      statistic = everything() ~ c("n", "p"),
      denominator = data
    )
  )

ard
```

```{r, echo=FALSE}
# Print ARD
withr::local_options(width = 9999)
print(ard, columns = "all", n = 40)
```

## Build Table

```{r tbl, message=FALSE, warning=FALSE, results='hide'}
tbl_scrn <- tbl_summary(
  data = data,
  include = "SCRNFL",
  statistic = SCRNFL ~ "{n}",
  missing = "no"
)

tbl_scrnfrs <- tbl_hierarchical(
  data = data,
  denominator = adsl,
  id = USUBJID,
  variables = "SCRNFRS",
  statistic = ~"{n} ({p}%)",
  label = list(..ard_hierarchical_overall.. = "Screening failures"),
  overall_row = TRUE
)

tbl_enrl_rand <- tbl_summary(
  data = data,
  include = c("ENRLFL", "RANDFL"),
  missing = "no"
)

tbl <- list(tbl_scrn, tbl_scrnfrs, tbl_enrl_rand) |>
  tbl_stack() |>
  modify_header(label = "**Disposition**", stat_0 = "**Trial A**") |>
  modify_column_indent("label", rows = !(variable %in% c("..ard_hierarchical_overall..", "SCRNFL", "ENRLFL", "RANDFL"))) |>
  remove_footnote_header(columns = everything())

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%'}
```
:::
 
  • This website as well as code examples are licensed under the Apache License, Version 2.0.
Cookie Preferences