Code
split_fun <- drop_split_levels
afun <- function(x, .var, .spl_context, ...) {
n_fun <- sum(!is.na(x), na.rm = TRUE)
if (n_fun == 0) {
mean_sd_fun <- c(NA, NA)
median_fun <- NA
min_max_fun <- c(NA, NA)
} else {
mean_sd_fun <- c(mean(x, na.rm = TRUE), sd(x, na.rm = TRUE))
median_fun <- median(x, na.rm = TRUE)
min_max_fun <- c(min(x), max(x))
}
is_chg <- .var == "CHG"
is_baseline <- .spl_context$value[which(.spl_context$split == "AVISIT")] == "BASELINE"
if (is_baseline && is_chg) n_fun <- mean_sd_fun <- median_fun <- min_max_fun <- NULL
in_rows(
"n" = n_fun,
"Mean (SD)" = mean_sd_fun,
"Median" = median_fun,
"Min - Max" = min_max_fun,
.formats = list("n" = "xx", "Mean (SD)" = "xx.xx (xx.xx)", "Median" = "xx.xx", "Min - Max" = "xx.xx - xx.xx"),
.format_na_strs = list("n" = "NE", "Mean (SD)" = "NE (NE)", "Median" = "NE", "Min - Max" = "NE - NE")
)
}
lyt <- basic_table(show_colcounts = TRUE) %>%
split_cols_by("ACTARM") %>%
split_rows_by("AVISIT", split_fun = split_fun, label_pos = "topleft", split_label = "\n\nAnalysis Visit") %>%
split_cols_by_multivar(
vars = c("AVAL", "CHG"),
varlabels = c("Value at Visit", "Change from\nBaseline")
) %>%
analyze_colvars(afun = afun)
result <- build_table(lyt = lyt, df = advs_f, alt_counts_df = adsl)
result
A: Drug X B: Placebo C: Combination
Change from Change from Change from
Value at Visit Baseline Value at Visit Baseline Value at Visit Baseline
Analysis Visit (N=134) (N=134) (N=134) (N=134) (N=132) (N=132)
———————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
SCREENING
n 134 0 134 0 132 0
Mean (SD) 99.92 (17.99) NE (NE) 101.88 (21.07) NE (NE) 100.48 (19.07) NE (NE)
Median 99.26 NE 100.22 NE 99.10 NE
Min - Max 54.22 - 152.98 NE - NE 48.15 - 148.03 NE - NE 42.22 - 149.95 NE - NE
BASELINE
n 134 134 132
Mean (SD) 96.50 (19.90) 101.10 (19.87) 102.77 (19.48)
Median 96.05 100.45 102.01
Min - Max 44.28 - 136.59 29.21 - 143.77 49.37 - 153.50
WEEK 1 DAY 8
n 134 134 134 134 132 132
Mean (SD) 100.65 (18.79) 4.14 (26.93) 99.19 (19.36) -1.92 (27.37) 97.14 (19.72) -5.63 (25.95)
Median 100.22 1.52 99.37 -2.79 94.19 -5.57
Min - Max 57.60 - 147.46 -50.92 - 74.84 59.28 - 141.21 -64.50 - 70.93 50.98 - 142.47 -55.15 - 56.11
WEEK 2 DAY 15
n 134 134 134 134 132 132
Mean (SD) 102.09 (19.62) 5.58 (29.38) 99.29 (21.11) -1.81 (31.11) 99.95 (20.85) -2.81 (29.10)
Median 103.59 7.82 100.57 -1.77 102.52 -5.68
Min - Max 54.73 - 150.85 -59.71 - 98.08 51.60 - 145.28 -71.00 - 92.43 37.06 - 138.92 -73.10 - 76.80
WEEK 3 DAY 22
n 134 134 134 134 132 132
Mean (SD) 101.78 (19.54) 5.28 (27.16) 97.73 (19.85) -3.37 (27.76) 99.86 (19.15) -2.91 (27.25)
Median 100.39 6.53 98.83 -5.79 100.06 -1.54
Min - Max 47.68 - 162.22 -64.46 - 76.64 36.25 - 142.78 -70.23 - 84.74 53.80 - 146.37 -74.30 - 67.46
WEEK 4 DAY 29
n 134 134 134 134 132 132
Mean (SD) 100.18 (20.18) 3.68 (27.21) 99.06 (17.75) -2.04 (26.59) 99.27 (20.12) -3.50 (27.62)
Median 98.17 3.00 97.98 -1.89 99.61 -0.46
Min - Max 48.52 - 153.41 -77.30 - 61.90 56.78 - 142.45 -82.96 - 89.87 46.87 - 146.12 -88.68 - 70.90
WEEK 5 DAY 36
n 134 134 134 134 132 132
Mean (SD) 101.42 (18.83) 4.92 (28.02) 95.92 (19.90) -5.19 (29.34) 97.73 (18.92) -5.04 (26.64)
Median 98.56 3.93 94.30 -7.18 98.09 -5.62
Min - Max 62.66 - 155.52 -63.05 - 78.66 51.06 - 151.52 -78.07 - 72.91 51.48 - 157.27 -76.13 - 86.42
Post-Baseline Last
n 134 134 134 134 132 132
Mean (SD) 101.42 (18.83) 4.92 (28.02) 95.92 (19.90) -5.19 (29.34) 97.73 (18.92) -5.04 (26.64)
Median 98.56 3.93 94.30 -7.18 98.09 -5.62
Min - Max 62.66 - 155.52 -63.05 - 78.66 51.06 - 151.52 -78.07 - 72.91 51.48 - 157.27 -76.13 - 86.42
Post-Baseline Minimum
n 134 134 134 134 132 132
Mean (SD) 78.98 (11.94) -17.52 (23.92) 75.77 (13.25) -25.33 (25.39) 76.35 (13.13) -26.41 (22.78)
Median 80.14 -13.96 75.71 -26.70 76.26 -27.17
Min - Max 47.68 - 110.54 -77.30 - 33.00 36.25 - 113.53 -82.96 - 69.23 37.06 - 112.35 -88.68 - 34.24
Post-Baseline Maximum
n 134 134 134 134 132 132
Mean (SD) 125.08 (12.28) 28.57 (23.20) 121.33 (12.01) 20.23 (23.64) 121.42 (12.09) 18.65 (22.74)
Median 124.20 29.14 120.80 18.74 122.55 16.93
Min - Max 94.06 - 162.22 -21.49 - 98.08 94.43 - 151.52 -34.95 - 92.43 79.39 - 157.27 -43.32 - 86.42