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

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

FDA Table 03

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

Code
# Load libraries & data -------------------------------------
library(dplyr)
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", "Subject noncompliance", "Consent withdrawn", "Other"
)
data <- adsl |>
  mutate(
    ENRLDT = RANDDT,
    SCRNFL = TRUE,
    SCRNFRS = factor(sample(scrnfail_reas_lvls, size = nrow(adsl), replace = TRUE),
      levels = scrnfail_reas_lvls
    ),
    ENRLFL = !is.na(ENRLDT),
    RANDFL = !is.na(RANDDT)
  )
data$SCRNFRS[data$SCRNFL == "N" | !is.na(data$ENRLDT)] <- NA
Code
ard <- data |>
  ard_stack(
    ard_tabulate_value(
      variables = SCRNFL,
      value = list(SCRNFL = TRUE),
      statistic = everything() ~ c("n")
    ),
    ard_tabulate(
      variables = SCRNFRS,
      statistic = everything() ~ c("n", "p"),
      denominator = data
    ),
    ard_tabulate_value(
      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 tabulate…         n          n   400       0              
2   SCRNFRS      Inclusio…  tabulate         n          n    26       0              
3   SCRNFRS      Inclusio…  tabulate         p          % 0.065    <fn>              
4   SCRNFRS      Subject …  tabulate         n          n    20       0              
5   SCRNFRS      Subject …  tabulate         p          %  0.05    <fn>              
6   SCRNFRS      Consent …  tabulate         n          n    30       0              
7   SCRNFRS      Consent …  tabulate         p          % 0.075    <fn>              
8   SCRNFRS          Other  tabulate         n          n    24       0              
9   SCRNFRS          Other  tabulate         p          %  0.06    <fn>              
10   ENRLFL           TRUE tabulate…         n          n   300       0              
11   ENRLFL           TRUE tabulate…         p          %  0.75    <fn>              
12   RANDFL           TRUE tabulate…         n          n   300       0              
13   RANDFL           TRUE tabulate…         p          %  0.75    <fn>              
Code
tbl_scrn <- tbl_summary(
  data = data,
  by = TRT01A,
  include = "SCRNFL",
  missing = "no",
  label = ~"Subjects screened"
)

tbl_scrnfrs <- tbl_hierarchical(
  data = data,
  denominator = adsl,
  id = USUBJID,
  by = TRT01A,
  variables = "SCRNFRS",
  label = list(..ard_hierarchical_overall.. = "Screening failures"),
  overall_row = TRUE
) |>
  modify_indent(columns = label, rows = row_type == "level", indent = 4L) |>
  modify_indent(columns = label, rows = variable == "SCRNFRS", indent = 8L)

tbl_enrl_rand <- tbl_summary(
  data = data,
  by = TRT01A,
  include = c("ENRLFL", "RANDFL"),
  missing = "no",
  label = list(ENRLFL = "Subjects enrolled", RANDFL = "Subjects randomized")
)

tbl <- list(tbl_scrn, tbl_scrnfrs, tbl_enrl_rand) |>
  tbl_stack() |>
  modify_header(label = "**Disposition**")

tbl

Source Code
---
title: Subject Screening and Enrollment, Screening Population, Trials A and B
subtitle: FDA Table 03
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(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", "Subject noncompliance", "Consent withdrawn", "Other"
)
data <- adsl |>
  mutate(
    ENRLDT = RANDDT,
    SCRNFL = TRUE,
    SCRNFRS = factor(sample(scrnfail_reas_lvls, size = nrow(adsl), replace = TRUE),
      levels = scrnfail_reas_lvls
    ),
    ENRLFL = !is.na(ENRLDT),
    RANDFL = !is.na(RANDDT)
  )
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_tabulate_value(
      variables = SCRNFL,
      value = list(SCRNFL = TRUE),
      statistic = everything() ~ c("n")
    ),
    ard_tabulate(
      variables = SCRNFRS,
      statistic = everything() ~ c("n", "p"),
      denominator = data
    ),
    ard_tabulate_value(
      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,
  by = TRT01A,
  include = "SCRNFL",
  missing = "no",
  label = ~"Subjects screened"
)

tbl_scrnfrs <- tbl_hierarchical(
  data = data,
  denominator = adsl,
  id = USUBJID,
  by = TRT01A,
  variables = "SCRNFRS",
  label = list(..ard_hierarchical_overall.. = "Screening failures"),
  overall_row = TRUE
) |>
  modify_indent(columns = label, rows = row_type == "level", indent = 4L) |>
  modify_indent(columns = label, rows = variable == "SCRNFRS", indent = 8L)

tbl_enrl_rand <- tbl_summary(
  data = data,
  by = TRT01A,
  include = c("ENRLFL", "RANDFL"),
  missing = "no",
  label = list(ENRLFL = "Subjects enrolled", RANDFL = "Subjects randomized")
)

tbl <- list(tbl_scrn, tbl_scrnfrs, tbl_enrl_rand) |>
  tbl_stack() |>
  modify_header(label = "**Disposition**")

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