Getting Started with Baseline Characteristics Table
baseline-character.Rmd
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:
-
prepare_base_cha
: prepare analysis raw datasets. -
format_base_char
: prepare analysis (mock) outdata with proper format. -
rtf_base_char
: transfer (mock) output dataset to RTF table.
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",
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 = "gender",
var = "SEX",
label = "Gender") |>
define_parameter(name = "race",
var = "RACE",
label = "Race") |>
define_analysis(name = "base_char",
title = "Participant Baseline Characteristics by Treatment Group",
label = "baseline characteristic table") |>
meta_build()
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
## List of 14
## $ meta :List of 7
## $ population : chr "apat"
## $ observation : chr "apat"
## $ parameter : chr "age;gender;race"
## $ n :'data.frame': 1 obs. of 6 variables:
## $ order : NULL
## $ group : chr "TRTA"
## $ reference_group: NULL
## $ char_n :List of 3
## $ char_var : chr [1:3] "AGE" "SEX" "RACE"
## $ char_prop :List of 3
## $ var_type :List of 3
## $ group_label : Factor w/ 3 levels "Placebo","Low Dose",..: 1 3 2
## $ analysis : chr "base_char"
outdata$n
## name n_1 n_2 n_3 n_9999 var_label
## 1 Participants in population 86 84 84 254 -----
outdata$char_n
## [[1]]
## name Placebo Low Dose High Dose Total var_label
## 1 <65 14 8 11 33 Age (years)
## 2 >80 30 29 18 77 Age (years)
## 3 65-80 42 47 55 144 Age (years)
## 4 <NA> <NA> <NA> <NA> <NA> Age (years)
## 5 Mean 75.2 75.7 74.4 75.1 Age (years)
## 6 SD 8.6 8.3 7.9 8.2 Age (years)
## 7 SE 0.9 0.9 0.9 0.5 Age (years)
## 8 Median 76.0 77.5 76.0 77.0 Age (years)
## 9 Min 52.0 51.0 56.0 51.0 Age (years)
## 10 Max 89.0 88.0 88.0 89.0 Age (years)
## 11 Q1 to Q3 69.25 to 81.75 71 to 82 70.75 to 80 70 to 81 Age (years)
## 12 Range 52 to 89 51 to 88 56 to 88 51 to 89 Age (years)
##
## [[2]]
## name Placebo Low Dose High Dose Total var_label
## 1 F 53 50 40 143 Gender
## 2 M 33 34 44 111 Gender
##
## [[3]]
## name Placebo Low Dose High Dose Total var_label
## 1 AMERICAN INDIAN OR ALASKA NATIVE 0 0 1 1 Race
## 2 BLACK OR AFRICAN AMERICAN 8 6 9 23 Race
## 3 WHITE 78 78 74 230 Race
outdata$char_var
## [1] "AGE" "SEX" "RACE"
outdata$char_prop
## [[1]]
## name Placebo Low Dose High Dose Total var_label
## 1 <65 16.27907 9.52381 13.09524 12.99213 Age (years)
## 2 >80 34.88372 34.52381 21.42857 30.31496 Age (years)
## 3 65-80 48.83721 55.95238 65.47619 56.69291 Age (years)
## 4 <NA> NA NA NA NA Age (years)
## 5 Mean NA NA NA NA Age (years)
## 6 SD NA NA NA NA Age (years)
## 7 SE NA NA NA NA Age (years)
## 8 Median NA NA NA NA Age (years)
## 9 Min NA NA NA NA Age (years)
## 10 Max NA NA NA NA Age (years)
## 11 Q1 to Q3 NA NA NA NA Age (years)
## 12 Range NA NA NA NA Age (years)
##
## [[2]]
## name Placebo Low Dose High Dose Total var_label
## 1 F 61.62791 59.52381 47.61905 56.29921 Gender
## 2 M 38.37209 40.47619 52.38095 43.70079 Gender
##
## [[3]]
## name Placebo Low Dose High Dose Total
## 1 AMERICAN INDIAN OR ALASKA NATIVE 0.000000 0.000000 1.190476 0.3937008
## 2 BLACK OR AFRICAN AMERICAN 9.302326 7.142857 10.714286 9.0551181
## 3 WHITE 90.697674 92.857143 88.095238 90.5511811
## var_label
## 1 Race
## 2 Race
## 3 Race
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)
outdata$tbl
## name n_1 p_1 n_2 p_2
## 1 Participants in population 86 <NA> 84 <NA>
## 2 <65 14 (16.28) 8 (9.52)
## 3 >80 30 (34.88) 29 (34.52)
## 4 65-80 42 (48.84) 47 (55.95)
## 5 <NA> <NA> <NA> <NA> <NA>
## 6 Mean 75.2 <NA> 75.7 <NA>
## 7 SD 8.6 <NA> 8.3 <NA>
## 8 SE 0.9 <NA> 0.9 <NA>
## 9 Median 76.0 <NA> 77.5 <NA>
## 10 Q1 to Q3 69.25 to 81.75 <NA> 71 to 82 <NA>
## 11 Range 52 to 89 <NA> 51 to 88 <NA>
## 12 F 53 (61.63) 50 (59.52)
## 13 M 33 (38.37) 34 (40.48)
## 14 AMERICAN INDIAN OR ALASKA NATIVE 0 (0.00) 0 (0.00)
## 15 BLACK OR AFRICAN AMERICAN 8 (9.30) 6 (7.14)
## 16 WHITE 78 (90.70) 78 (92.86)
## n_3 p_3 n_9999 p_9999 var_label
## 1 84 <NA> 254 <NA> -----
## 2 11 (13.10) 33 (12.99) Age (years)
## 3 18 (21.43) 77 (30.31) Age (years)
## 4 55 (65.48) 144 (56.69) Age (years)
## 5 <NA> <NA> <NA> <NA> Age (years)
## 6 74.4 <NA> 75.1 <NA> Age (years)
## 7 7.9 <NA> 8.2 <NA> Age (years)
## 8 0.9 <NA> 0.5 <NA> Age (years)
## 9 76.0 <NA> 77.0 <NA> Age (years)
## 10 70.75 to 80 <NA> 70 to 81 <NA> Age (years)
## 11 56 to 88 <NA> 51 to 89 <NA> Age (years)
## 12 40 (47.62) 143 (56.30) Gender
## 13 44 (52.38) 111 (43.70) Gender
## 14 1 (1.19) 1 (0.39) Race
## 15 9 (10.71) 23 (9.06) Race
## 16 74 (88.10) 230 (90.55) Race
outdata <-
outdata |> format_base_char(display_col = c("n", "prop"), digits_prop = 3)
outdata$tbl
## name n_1 p_1 n_2 p_2
## 1 Participants in population 86 <NA> 84 <NA>
## 2 <65 14 (16.279) 8 (9.524)
## 3 >80 30 (34.884) 29 (34.524)
## 4 65-80 42 (48.837) 47 (55.952)
## 5 <NA> <NA> <NA> <NA> <NA>
## 6 Mean 75.2 <NA> 75.7 <NA>
## 7 SD 8.6 <NA> 8.3 <NA>
## 8 SE 0.9 <NA> 0.9 <NA>
## 9 Median 76.0 <NA> 77.5 <NA>
## 10 Q1 to Q3 69.25 to 81.75 <NA> 71 to 82 <NA>
## 11 Range 52 to 89 <NA> 51 to 88 <NA>
## 12 F 53 (61.628) 50 (59.524)
## 13 M 33 (38.372) 34 (40.476)
## 14 AMERICAN INDIAN OR ALASKA NATIVE 0 (0.000) 0 (0.000)
## 15 BLACK OR AFRICAN AMERICAN 8 (9.302) 6 (7.143)
## 16 WHITE 78 (90.698) 78 (92.857)
## n_3 p_3 var_label
## 1 84 <NA> -----
## 2 11 (13.095) Age (years)
## 3 18 (21.429) Age (years)
## 4 55 (65.476) Age (years)
## 5 <NA> <NA> Age (years)
## 6 74.4 <NA> Age (years)
## 7 7.9 <NA> Age (years)
## 8 0.9 <NA> Age (years)
## 9 76.0 <NA> Age (years)
## 10 70.75 to 80 <NA> Age (years)
## 11 56 to 88 <NA> Age (years)
## 12 40 (47.619) Gender
## 13 44 (52.381) Gender
## 14 1 (1.190) Race
## 15 9 (10.714) Race
## 16 74 (88.095) Race
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 = "base_char.rtf"
)
## The outdata is saved in/tmp/Rtmp5CkYJa/file18aa2b2ccfda.Rdata
## The output is saved in/home/runner/work/metalite.sl/metalite.sl/vignettes/base_char.rtf
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:
-
prepare_base_char_subgroup()
: prepare analysis raw datasets. -
format_base_char_subgroup()
: prepare analysis (mock) outdata with proper format. -
rtf_base_char_subgroup()
: transfer (mock) output dataset to RTF table.
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",
population = "apat",
observation = "apat",
parameter = "age;gender;race"
) |>
add_plan(
analysis = "base_char_subgroup",
population = "apat",
observation = "apat",
parameter = "age"
)
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 = "gender",
var = "SEX",
label = "Gender") |>
define_parameter(name = "race",
var = "RACE",
label = "Race") |>
define_analysis(name = "base_char",
title = "Participant Baseline Characteristics by Treatment Group",
label = "baseline characteristic table") |>
define_analysis(name = "base_char_subgroup",
title = "Participant by Age Category and Sex",
label = "baseline characteristic sub group table") |>
meta_build()
Analysis preparation
meta <- meta_sl_example()
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:
-
subgroup_var
: a character value of subgroup variable name in observation data saved in meta$data_observation. -
subgroup_header
: a character vector for column header hierarchy. The first element will be the first level header and the second element will be second level header.
outdata <- prepare_base_char_subgroup(
meta,
population = "apat",
parameter = "age",
subgroup_var = "TRTA",
subgroup_header = c("SEX", "TRTA"),
display_subgroup_total = TRUE
)
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
tbl <- format_base_char_subgroup(outdata)
head(tbl$tbl)
Output as RTF
rtf_base_char_subgroup
to generate RTF output
outdata |>
format_base_char_subgroup() |>
rtf_base_char_subgroup(
source = "Source: [CDISCpilot: adam-adsl]",
path_outdata = tempfile(fileext = ".Rdata"),
path_outtable = "base_char_subgroup.rtf"
)