knitr::opts_chunk$set(
  comment = "#>",
  collapse = TRUE,
  out.width = "100%",
  dpi = 150
)
library(metalite.ae)

Overview

The objective of this tutorial is to generate a production-ready AE summary. It extends examples shown in the AE summary chapter of the R for Clinical Study Reports and Submission book.

The AE summary analysis entails the creation of tables that summarize adverse events information. To accomplish this using metalite.ae, three essential functions are required:

There is one optional function to extend AE summary analysis:

An example output:

knitr::include_graphics("pdf/ae0summary1.pdf")

Example data

Within metalite.ae, we utilized the ADSL and ADAE datasets from the metalite package to create an illustrative dataset. The metadata structure remains consistent across all analysis examples within metalite.ae. Additional information can be accessed on the metalite package website.

meta <- meta_ae_example()

Click to show the output

meta

Analysis preparation

The function prepare_ae_summary() is used to create a dataset for AE summary analysis by utilizing predefined keywords specified in the example data meta.

The resulting output of the function is an outdata object, which comprises a collection of raw datasets for analysis and reporting.

outdata <- prepare_ae_summary(
  meta,
  population = "apat",
  observation = "wk12",
  parameter = "any;rel;ser"
)
outdata

The resulting dataset contains frequently used statistics, with variables indexed according to the order specified in outdata$group.

outdata$group

The row is indexed according to the order of outdata$name.

head(data.frame(outdata$order, outdata$name))
outdata$n_pop
head(outdata$n)
head(outdata$prop)
head(outdata$diff)

Format output

Once the raw analysis results are obtained, the format_ae_summary() function can be employed to prepare the outdata, ensuring its compatibility with production-ready RTF tables.

tbl <- outdata |> format_ae_summary()
tbl$tbl

Additional statistics

By using the display argument, we can choose specific statistics to include. For instance, we have the option to incorporate the risk difference.

tbl <- outdata |> format_ae_summary(display = c("n", "prop", "diff"))
tbl$tbl

To perform advanced analysis, the extend_ae_specific_inference() function is utilized. For instance, we can incorporate a 95% confidence interval based on the Miettinen and Nurminen (M&N) method. Further information regarding the M&N method can be found in the rate compare vignette.

tbl <- outdata |>
  extend_ae_specific_inference() |>
  format_ae_summary(display = c("n", "prop", "diff", "diff_ci"))

tbl$tbl

Mock data preparation

The mock argument facilitates the creation of a mock table with ease.

Please note that the intention of the mock argument is not to provide an all-encompassing mock table template. Instead, it serves as a convenient method to assist users in generating a mock table that closely resembles the desired output layout. To develop a more versatile mock table generation tool, further efforts are necessary. This could potentially involve the creation of a dedicated mock table generation package or similar solutions.

tbl <- outdata |> format_ae_summary(mock = TRUE)
tbl$tbl

RTF tables

The last step is to prepare the RTF table using tlf_ae_summary().

outdata |>
  format_ae_summary() |>
  tlf_ae_summary(
    source = "Source:  [CDISCpilot: adam-adsl; adae]",
    analysis = "ae_summary", # Provide analysis type defined in meta$analysis
    path_outtable = "rtf/ae0summary1.rtf"
  )
knitr::include_graphics("pdf/ae0summary1.pdf")

The tlf_ae_summary() function also provides some commonly used argument to customize the table.

outdata |>
  format_ae_summary() |>
  tlf_ae_summary(
    source = "Source:  [CDISCpilot: adam-adsl; adae]",
    analysis = "ae_summary", # Provide analysis type defined in meta$analysis
    col_rel_width = c(6, rep(1, 8)),
    text_font_size = 8,
    orientation = "landscape",
    path_outtable = "rtf/ae0summary2.rtf"
  )
knitr::include_graphics("pdf/ae0summary2.pdf")

The empty table can be generated if there is not result to display.

knitr::include_graphics("pdf/empty_ae0specific.pdf")

The mock table can also be generated.

outdata |>
  format_ae_summary(mock = TRUE) |>
  tlf_ae_summary(
    source = "Source:  [CDISCpilot: adam-adsl; adae]",
    analysis = "ae_summary", # Provide analysis type defined in meta$analysis
    path_outtable = "rtf/mock_ae0summary1.rtf"
  )
knitr::include_graphics("pdf/mock_ae0summary1.pdf")


Merck/metalite.ae documentation built on Feb. 10, 2025, 5:03 p.m.