as_result_df()
and ARDs depend on the content of the table, so it is possible to modify the table to customize the output. For example, we can add some user-defined statistics with custom names:
# rcell and in_rows are the core of any analysis function
rc <- rcell(c(1, 2), stat_names = c("Rand1", "Rand2"))
print(obj_stat_names(rc)) # c("Rand1", "Rand2")
# [1] "Rand1" "Rand2"
rc_row <- in_rows(
.list = list(a = c(NA, 1), b = c(1, NA)),
.formats = c("xx - xx", "xx.x - xx.x"),
.format_na_strs = list(c("asda", "lkjklj")),
.stat_names = list(c("A", "B"), c("B", "C"))
)
# Only a getter for this object
print(obj_stat_names(rc_row)) # list(a = c("A", "B"), b = c("B", "C"))
# $a
# [1] "A" "B"
#
# $b
# [1] "B" "C"
# if c("A", "B"), one for each row
# if single list, duplicated
rc_row <- in_rows(
.list = list(a = c(NA, 1), b = c(1, NA)),
.formats = c("xx - xx", "xx.x - xx.x"),
.format_na_strs = list(c("asda", "lkjklj")),
.stat_names = c("A", "B")
)
print(obj_stat_names(rc_row)) # c("A", "B") # one for each row
# $a
# [1] "A"
#
# $b
# [1] "B"
print(lapply(rc_row, obj_stat_names)) # identical to above + row names
# $a
# [1] "A"
#
# $b
# [1] "B"
rc_row <- in_rows(
.list = list(a = c(NA, 1), b = c(1, NA)),
.formats = c("xx - xx", "xx.x - xx.x"),
.format_na_strs = list(c("asda", "lkjklj")),
.stat_names = list(c("A", "B")) # It is duplicated, check it yourself!
)
mean_sd_custom <- function(x) {
mean <- mean(x, na.rm = FALSE)
sd <- sd(x, na.rm = FALSE)
rcell(c(mean, sd),
label = "Mean (SD)", format = "xx.x (xx.x)" # ,
# stat_names = c("Mean", "SD")
)
}
counts_percentage_custom <- function(x) {
cnts <- table(x)
out <- lapply(cnts, function(x) {
perc <- x / sum(cnts)
rcell(c(x, perc), format = "xx. (xx.%)")
})
in_rows(
.list = as.list(out), .labels = names(cnts),
.stat_names = list(c("Count", "Percentage"))
)
}
lyt <- basic_table(show_colcounts = TRUE, colcount_format = "N=xx") %>%
split_cols_by("ARM", split_fun = keep_split_levels(c("A: Drug X", "B: Placebo"))) %>%
analyze(vars = "AGE", afun = mean_sd_custom) %>%
analyze(vars = "SEX", afun = counts_percentage_custom)
tbl <- build_table(lyt, ex_adsl)
as_result_df(tbl, make_ard = TRUE)
# group1 group1_level variable variable_level variable_label stat_name
# 1 ARM A: Drug X AGE Mean (SD) Mean (SD) <NA>
# 2 ARM A: Drug X AGE Mean (SD) Mean (SD) <NA>
# 3 ARM A: Drug X SEX F F Count
# 4 ARM A: Drug X SEX F F Percentage
# 5 ARM A: Drug X SEX M M Count
# 6 ARM A: Drug X SEX M M Percentage
# 7 ARM A: Drug X SEX U U Count
# 8 ARM A: Drug X SEX U U Percentage
# 9 ARM A: Drug X SEX UNDIFFERENTIATED UNDIFFERENTIATED Count
# 10 ARM A: Drug X SEX UNDIFFERENTIATED UNDIFFERENTIATED Percentage
# 11 ARM B: Placebo AGE Mean (SD) Mean (SD) <NA>
# 12 ARM B: Placebo AGE Mean (SD) Mean (SD) <NA>
# 13 ARM B: Placebo SEX F F Count
# 14 ARM B: Placebo SEX F F Percentage
# 15 ARM B: Placebo SEX M M Count
# 16 ARM B: Placebo SEX M M Percentage
# 17 ARM B: Placebo SEX U U Count
# 18 ARM B: Placebo SEX U U Percentage
# 19 ARM B: Placebo SEX UNDIFFERENTIATED UNDIFFERENTIATED Count
# 20 ARM B: Placebo SEX UNDIFFERENTIATED UNDIFFERENTIATED Percentage
# stat stat_string
# 1 33.768656716 33.8
# 2 6.553325712 6.6
# 3 79.000000000 79
# 4 0.589552239 59
# 5 51.000000000 51
# 6 0.380597015 38
# 7 3.000000000 3
# 8 0.022388060 2
# 9 1.000000000 1
# 10 0.007462687 1
# 11 35.432835821 35.4
# 12 7.895413879 7.9
# 13 77.000000000 77
# 14 0.574626866 57
# 15 55.000000000 55
# 16 0.410447761 41
# 17 2.000000000 2
# 18 0.014925373 1
# 19 0.000000000 0
# 20 0.000000000 0
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4