Demographic Table
Introduction
This guide will show you how pharmaverse packages, along with some from tidyverse, can be used to create a Demographic table, using the {pharmaverseadam}
ADSL
data as an input.
The packages used with a brief description of their purpose are as follows:
Load Data and Required pharmaverse Package
After installation of packages, the first step is to load our pharmaverse packages and input data. Here, we are going to encode missing entries in a data frame adsl
.
Note that {tern}
depends on {rtables}
so the latter is automatically attached.
Start preprocessing
Now we will add some pre-processing to create some extra formatted variables ready for display in the table.
# Create categorical variables
adsl <- adsl %>%
mutate(
SEX = factor(case_when(
SEX == "M" ~ "Male",
SEX == "F" ~ "Female",
SEX == "U" ~ "Unknown",
SEX == "UNDIFFERENTIATED" ~ "Undifferentiated"
)),
AGEGR1 = factor(
case_when(
between(AGE, 18, 40) ~ "18-40",
between(AGE, 41, 64) ~ "41-64",
AGE > 64 ~ ">=65"
),
levels = c("18-40", "41-64", ">=65")
)
)
Demographic table
Now we create the demographic table.
vars <- c("AGE", "AGEGR1", "SEX", "RACE")
var_labels <- c(
"Age (yr)",
"Age group",
"Sex",
"Race"
)
lyt <- basic_table(show_colcounts = TRUE) %>%
split_cols_by(var = "ACTARM") %>%
add_overall_col("All Patients") %>%
analyze_vars(
vars = vars,
var_labels = var_labels
)
result <- build_table(lyt, adsl)
result
Placebo Screen Failure Xanomeline High Dose Xanomeline Low Dose All Patients
(N=86) (N=52) (N=72) (N=96) (N=306)
—————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
Age (yr)
n 86 52 72 96 306
Mean (SD) 75.2 (8.6) 75.1 (9.7) 73.8 (7.9) 76.0 (8.1) 75.1 (8.5)
Median 76.0 76.0 75.5 78.0 77.0
Min - Max 52.0 - 89.0 50.0 - 89.0 56.0 - 88.0 51.0 - 88.0 50.0 - 89.0
Age group
n 86 52 72 96 306
18-40 0 0 0 0 0
41-64 14 (16.3%) 9 (17.3%) 11 (15.3%) 8 (8.3%) 42 (13.7%)
>=65 72 (83.7%) 43 (82.7%) 61 (84.7%) 88 (91.7%) 264 (86.3%)
Sex
n 86 52 72 96 306
Female 53 (61.6%) 36 (69.2%) 35 (48.6%) 55 (57.3%) 179 (58.5%)
Male 33 (38.4%) 16 (30.8%) 37 (51.4%) 41 (42.7%) 127 (41.5%)
Race
n 86 52 72 96 306
AMERICAN INDIAN OR ALASKA NATIVE 0 1 (1.9%) 1 (1.4%) 0 2 (0.7%)
ASIAN 0 2 (3.8%) 0 0 2 (0.7%)
BLACK OR AFRICAN AMERICAN 8 (9.3%) 6 (11.5%) 9 (12.5%) 6 (6.2%) 29 (9.5%)
WHITE 78 (90.7%) 43 (82.7%) 62 (86.1%) 90 (93.8%) 273 (89.2%)