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

FDA Table 45

Subjects With Adverse Events by Female-Specific OCMQ (Broad) and Preferred Term, Female Safety Population, Pooled Analysis (or Trial X)

table
FDA
safety
adverse events
  • Table Preview
  • Setup
  • Build Table
  • Build ARD

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

adsl <- random.cdisc.data::cadsl
adae <- random.cdisc.data::cadae

set.seed(1)
adae <- rename(adae, OCMQ01SC = SMQ01SC, OCMQ01NAM = SMQ01NAM)
levels(adae$OCMQ01SC) <- c("BROAD", "NARROW")
adae$OCMQ01SC[is.na(adae$OCMQ01SC)] <- "NARROW"
adae$OCMQ01NAM <- factor(adae$OCMQ01NAM, levels = c(
  unique(adae$OCMQ01NAM), "Abnormal Uterine Bleeding", "Amenorrhea",
  "Bacterial Vaginosis", "Decreased Menstrual Bleeding"
))
adae$OCMQ01NAM[adae$SEX == "F"] <- as.factor(
  sample(c(
    "Abnormal Uterine Bleeding", "Amenorrhea",
    "Bacterial Vaginosis", "Decreased Menstrual Bleeding"
  ), sum(adae$SEX == "F"), replace = TRUE)
)

# Pre-processing --------------------------------------------
data <- adae |>
  filter(
    SAFFL == "Y",
    SEX == "F",
    OCMQ01SC == "BROAD"
  ) |>
  select(OCMQ01SC, TRT01A, OCMQ01NAM, AEDECOD, USUBJID) |>
  # setting an explicit level for NA values so empty strata combinations are shown.
  mutate(across(everything(), ~ {
    if (anyNA(.)) {
      forcats::fct_na_value_to_level(as.factor(.), level = "<Missing>")
    } else {
      .
    }
  }))

# denominator values include only Female subjects in the arm with AEs
denom <- data |> distinct(USUBJID, TRT01A)
Code
tbl <- data |>
  tbl_hierarchical(
    by = TRT01A,
    variables = c(OCMQ01NAM, AEDECOD),
    id = USUBJID,
    denominator = denom,
    # variables to calculate rates for
    include = c(AEDECOD),
    label = list(
      OCMQ01NAM ~ "OCMQ (Broad)",
      AEDECOD ~ "Preferred Term"
    )
  )

tbl

Code
ard <- gather_ard(tbl)
ard
$tbl_hierarchical
{cards} data frame: 81 x 15
   group1 group1_level    group2 group2_level variable variable_level   context stat_name stat_label  stat stat_fmt fmt_fun warning error gts_column
1    <NA>                   <NA>                TRT01A      A: Drug X  tabulate         n          n    47       47       0                   stat_1
2    <NA>                   <NA>                TRT01A      A: Drug X  tabulate         N          N   140      140       0                   stat_1
3    <NA>                   <NA>                TRT01A      A: Drug X  tabulate         p          % 0.336     33.6    <fn>                   stat_1
4    <NA>                   <NA>                TRT01A      B: Place…  tabulate         n          n    51       51       0                   stat_2
5    <NA>                   <NA>                TRT01A      B: Place…  tabulate         N          N   140      140       0                   stat_2
6    <NA>                   <NA>                TRT01A      B: Place…  tabulate         p          % 0.364     36.4    <fn>                   stat_2
7    <NA>                   <NA>                TRT01A      C: Combi…  tabulate         n          n    42       42       0                   stat_3
8    <NA>                   <NA>                TRT01A      C: Combi…  tabulate         N          N   140      140       0                   stat_3
9    <NA>                   <NA>                TRT01A      C: Combi…  tabulate         p          %   0.3     30.0    <fn>                   stat_3
10 TRT01A    A: Drug X OCMQ01NAM    Abnormal…  AEDECOD      dcd B.2.… hierarch…         n          n     6        6    <fn>                   stat_1
ℹ 71 more rows
ℹ Use `print(n = ...)` to see more rows
Source Code
---
title: FDA Table 45
subtitle: Subjects With Adverse Events by Female-Specific OCMQ (Broad) and Preferred Term, Female Safety Population, Pooled Analysis (or Trial X)
categories: [table, FDA, safety, adverse events]
---

::: panel-tabset
## Table Preview

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

## Setup

```{r setup, message=FALSE}
# Load libraries & data -------------------------------------
library(dplyr)
library(cards)
library(gtsummary)

adsl <- random.cdisc.data::cadsl
adae <- random.cdisc.data::cadae

set.seed(1)
adae <- rename(adae, OCMQ01SC = SMQ01SC, OCMQ01NAM = SMQ01NAM)
levels(adae$OCMQ01SC) <- c("BROAD", "NARROW")
adae$OCMQ01SC[is.na(adae$OCMQ01SC)] <- "NARROW"
adae$OCMQ01NAM <- factor(adae$OCMQ01NAM, levels = c(
  unique(adae$OCMQ01NAM), "Abnormal Uterine Bleeding", "Amenorrhea",
  "Bacterial Vaginosis", "Decreased Menstrual Bleeding"
))
adae$OCMQ01NAM[adae$SEX == "F"] <- as.factor(
  sample(c(
    "Abnormal Uterine Bleeding", "Amenorrhea",
    "Bacterial Vaginosis", "Decreased Menstrual Bleeding"
  ), sum(adae$SEX == "F"), replace = TRUE)
)

# Pre-processing --------------------------------------------
data <- adae |>
  filter(
    SAFFL == "Y",
    SEX == "F",
    OCMQ01SC == "BROAD"
  ) |>
  select(OCMQ01SC, TRT01A, OCMQ01NAM, AEDECOD, USUBJID) |>
  # setting an explicit level for NA values so empty strata combinations are shown.
  mutate(across(everything(), ~ {
    if (anyNA(.)) {
      forcats::fct_na_value_to_level(as.factor(.), level = "<Missing>")
    } else {
      .
    }
  }))

# denominator values include only Female subjects in the arm with AEs
denom <- data |> distinct(USUBJID, TRT01A)
```

## Build Table

```{r tbl, results = 'hide'}
tbl <- data |>
  tbl_hierarchical(
    by = TRT01A,
    variables = c(OCMQ01NAM, AEDECOD),
    id = USUBJID,
    denominator = denom,
    # variables to calculate rates for
    include = c(AEDECOD),
    label = list(
      OCMQ01NAM ~ "OCMQ (Broad)",
      AEDECOD ~ "Preferred Term"
    )
  )

tbl
```

```{r eval=FALSE, include=FALSE}
gt::gtsave(as_gt(tbl), filename = "result.png")
```

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

## 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, columns = "all")
```
:::
 
  • This website as well as code examples are licensed under the Apache License, Version 2.0.
Cookie Preferences