Baseline Characteristics Table

library(metalite)
library(metalite.sl)

Create Baseline Characteristic Table

The baseline characteristic analysis aims to provide tables to summarize details of participants. The development of baseline characteristic analysis involves functions:

Build a metadata

adsl <- r2rtf::r2rtf_adsl
adsl$TRTA <- adsl$TRT01A
adsl$TRTA <- factor(
  adsl$TRTA,
  levels = c("Placebo", "Xanomeline Low Dose", "Xanomeline High Dose"),
  labels = c("Placebo", "Low Dose", "High Dose")
)
meta <- meta_sl(
  dataset_population = adsl,
  population_term = "apat",
  parameter_term = "age;gender;race",
  parameter_var = "AGE^AGEGR1;SEX;RACE",
  treatment_group = "TRTA"
)

Click to show the output

meta

Analysis preparation

The input of the function prepare_base_char() is a meta object created by the metalite package.

outdata <- meta |>
  prepare_base_char(parameter = "age;gender;race")

outdata

Click to show the output

outdata$n
outdata$char_n
outdata$char_var
outdata$char_prop

Format the numbers

format_base_char to prepare analysis dataset before generate RTF output

outdata <-
  outdata |> format_base_char(
    display_col = c("n", "prop", "total"),
    digits_prop = 2
  )

Click to show the output

outdata$tbl

Output as RTF

rtf_base_char to generate RTF output

outdata |> rtf_base_char(
  source = "Source: [CDISCpilot: adam-adsl]",
  path_outdata = tempfile(fileext = ".Rdata"),
  path_outtable = "outtable/base0char.rtf"
)
knitr::include_graphics("pdf/base0char.pdf")

Create Baseline Characteristic Table for Subgroup Analysis

The baseline characteristic subgroup analysis aims to provide tables to summarize details of participants by subgroup. The development of baseline characteristic subgroup analysis involves functions:

Build a metadata

adsl <- r2rtf::r2rtf_adsl
adsl$TRTA <- adsl$TRT01A
adsl$TRTA <- factor(
  adsl$TRTA,
  levels = c("Placebo", "Xanomeline Low Dose", "Xanomeline High Dose"),
  labels = c("Placebo", "Low Dose", "High Dose")
)
plan <- plan(
  analysis = "base_char_subgroup",
  population = "apat",
  observation = "apat",
  parameter = "age;gender;race"
)
meta <- meta_adam(
  population = adsl,
  observation = adsl
) |>
  define_plan(plan = plan) |>
  define_population(
    name = "apat",
    group = "TRTA",
    subset = quote(SAFFL == "Y"),
    var = c("USUBJID", "TRTA", "SAFFL", "AGEGR1", "SEX", "RACE")
  ) |>
  define_parameter(
    name = "age",
    var = "AGE",
    label = "Age (years)",
    vargroup = "AGEGR1"
  ) |>
  define_parameter(
    name = "race",
    var = "RACE",
    label = "Race"
  ) |>
  define_analysis(
    name = "base_char_subgroup",
    title = "Participant by Age Category and Sex",
    label = "baseline characteristic sub group table"
  ) |>
  meta_build()

Click to show the output

meta

Analysis preparation

The input of the function prepare_base_char_subgroup() is a meta object created by the metalite package.

The output of the function is an outdata object containing a list of analysis raw datasets. Key arguments are:

outdata <- prepare_base_char_subgroup(
  meta,
  population = "apat",
  parameter = "age;race",
  subgroup_var = "TRTA",
  subgroup_header = c("SEX", "TRTA"),
  display_subgroup_total = TRUE
)

Click to show the output The output dataset contains commonly used statistics within each subgroup_var.

outdata$out_all$`Placebo`
outdata$out_all$`High Dose`
outdata$out_all$`Low Dose`

The information about subgroup saved with outdata$group and outdata$subgroup.

outdata$group
outdata$subgroup

n_pop: participants in population within each subgroup_var.

outdata$out_all$`Placebo`$n
outdata$out_all$`High Dose`$n
outdata$out_all$`Low Dose`$n

Format output

format_base_char_subgroup to prepare analysis dataset before generate RTF output

outdata <- format_base_char_subgroup(outdata)

Click to show the output

outdata$tbl

Output as RTF

rtf_base_char_subgroup to generate RTF output

outdata |>
  rtf_base_char_subgroup(
    source = "Source:  [CDISCpilot: adam-adsl]",
    path_outdata = tempfile(fileext = ".Rdata"),
    path_outtable = "outtable/base0charsubgroup.rtf"
  )
knitr::include_graphics("pdf/base0charsubgroup.pdf")


Try the metalite.sl package in your browser

Any scripts or data that you put into this service are public.

metalite.sl documentation built on April 3, 2025, 8:52 p.m.