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

FDA Table 02

Baseline Demographic and Clinical Characteristics, Safety Population, Pooled Analyses

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

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

adsl <- random.cdisc.data::cadsl |>
  mutate(
    AGEGR1 = factor(
      dplyr::case_when(
        AGE >= 17 & AGE < 65 ~ ">=17 to <65",
        AGE >= 65 & AGE < 75 ~ "65-74",
        AGE >= 75 ~ ">=75"
      ),
      levels = c(">=17 to <65", "65-74", ">=75")
    )
  )

# Pre-processing --------------------------------------------
# Filter for the safety population, x
data <- adsl |>
  filter(SAFFL == "Y")
Code
tbl <- data |>
  tbl_summary(
    by = "ARM",
    include = c("SEX", "AGE", "AGEGR1", "ETHNIC", "RACE", "BMRKR1", "BMRKR2"),
    type = all_continuous() ~ "continuous2", # arranges statistics into multiple lines
    statistic = list(
      all_continuous() ~ c(
        "{mean} ({sd})",
        "{median} ({min}, {max})"
      ),
      all_categorical() ~ "{n} ({p}%)"
    ),
    label = list(AGEGR1 = "Age Group, Years")
  ) |>
  add_overall(last = TRUE, col_label = "**Total Population**  \nN = {N}") |>
  # remove default footnote
  gtsummary::remove_footnote_header(columns = everything())

Code
ard <- gather_ard(tbl)
ard
$tbl_summary
{cards} data frame: 347 x 12
   group1 group1_level variable variable_level   context stat_name stat_label  stat fmt_fn warning error gts_column
1     ARM    A: Drug X      SEX              F categori…         n          n    79   <fn>                   stat_1
2     ARM    A: Drug X      SEX              F categori…         N          N   134   <fn>                   stat_1
3     ARM    A: Drug X      SEX              F categori…         p          %  0.59   <fn>                   stat_1
4     ARM    A: Drug X      SEX              M categori…         n          n    55   <fn>                   stat_1
5     ARM    A: Drug X      SEX              M categori…         N          N   134   <fn>                   stat_1
6     ARM    A: Drug X      SEX              M categori…         p          %  0.41   <fn>                   stat_1
7     ARM    A: Drug X     RACE          ASIAN categori…         n          n    68   <fn>                   stat_1
8     ARM    A: Drug X     RACE          ASIAN categori…         N          N   134   <fn>                   stat_1
9     ARM    A: Drug X     RACE          ASIAN categori…         p          % 0.507   <fn>                   stat_1
10    ARM    A: Drug X     RACE      BLACK OR… categori…         n          n    31   <fn>                   stat_1
ℹ 337 more rows
ℹ Use `print(n = ...)` to see more rows

$add_overall
{cards} data frame: 125 x 10
   variable variable_level   context stat_name stat_label  stat fmt_fn warning error gts_column
1       SEX              F categori…         n          n   231   <fn>                   stat_0
2       SEX              F categori…         N          N   400   <fn>                   stat_0
3       SEX              F categori…         p          % 0.578   <fn>                   stat_0
4       SEX              M categori…         n          n   169   <fn>                   stat_0
5       SEX              M categori…         N          N   400   <fn>                   stat_0
6       SEX              M categori…         p          % 0.423   <fn>                   stat_0
7      RACE          ASIAN categori…         n          n   208   <fn>                   stat_0
8      RACE          ASIAN categori…         N          N   400   <fn>                   stat_0
9      RACE          ASIAN categori…         p          %  0.52   <fn>                   stat_0
10     RACE      BLACK OR… categori…         n          n    91   <fn>                   stat_0
ℹ 115 more rows
ℹ Use `print(n = ...)` to see more rows
Source Code
---
title: FDA Table 02
subtitle: Baseline Demographic and Clinical Characteristics, Safety Population, Pooled Analyses
categories: [table, FDA, safety, demographics]
---

::: 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)

adsl <- random.cdisc.data::cadsl |>
  mutate(
    AGEGR1 = factor(
      dplyr::case_when(
        AGE >= 17 & AGE < 65 ~ ">=17 to <65",
        AGE >= 65 & AGE < 75 ~ "65-74",
        AGE >= 75 ~ ">=75"
      ),
      levels = c(">=17 to <65", "65-74", ">=75")
    )
  )

# Pre-processing --------------------------------------------
# Filter for the safety population, x
data <- adsl |>
  filter(SAFFL == "Y")
```

## Build Table

```{r tbl, results='hide'}
tbl <- data |>
  tbl_summary(
    by = "ARM",
    include = c("SEX", "AGE", "AGEGR1", "ETHNIC", "RACE", "BMRKR1", "BMRKR2"),
    type = all_continuous() ~ "continuous2", # arranges statistics into multiple lines
    statistic = list(
      all_continuous() ~ c(
        "{mean} ({sd})",
        "{median} ({min}, {max})"
      ),
      all_categorical() ~ "{n} ({p}%)"
    ),
    label = list(AGEGR1 = "Age Group, Years")
  ) |>
  add_overall(last = TRUE, col_label = "**Total Population**  \nN = {N}") |>
  # remove default footnote
  gtsummary::remove_footnote_header(columns = everything())
```

```{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