Arguments
- lyt
(
layout
)
input layout where analyses will be added to.- var
(
string
)
single variable name that is passed byrtables
when requested by a statistics function.- groups_list
(named
list
ofcharacter
)
specifies the new group levels via the names and the levels that belong to it in the character vectors that are elements of the list.- ref_group
(
data frame
orvector
)
the data corresponding to the reference group.- ...
additional arguments, see note section.
Note
The ellipse (...
) conveys arguments to rtables::split_cols_by()
in order, for instance, to control formats (format
), add a joint column
for all groups (incl_all
).
Examples
library(rtables)
# 1 - Basic use
# Without group combination `split_cols_by_groups` is
# equivalent to [rtables::split_cols_by()].
basic_table() %>%
split_cols_by_groups("ARM") %>%
add_colcounts() %>%
analyze("AGE") %>%
build_table(DM)
#> A: Drug X B: Placebo C: Combination
#> (N=121) (N=106) (N=129)
#> ——————————————————————————————————————————————
#> Mean 34.91 33.02 34.57
# Add a reference column.
basic_table() %>%
split_cols_by_groups("ARM", ref_group = "B: Placebo") %>%
add_colcounts() %>%
analyze(
"AGE",
afun = function(x, .ref_group, .in_ref_col) {
if (.in_ref_col) {
in_rows("Diff Mean" = rcell(NULL))
} else {
in_rows("Diff Mean" = rcell(mean(x) - mean(.ref_group), format = "xx.xx"))
}
}
) %>%
build_table(DM)
#> B: Placebo A: Drug X C: Combination
#> (N=106) (N=121) (N=129)
#> ———————————————————————————————————————————————————
#> Diff Mean 1.89 1.55
# 2 - Adding group specification
# Manual preparation of the groups.
groups <- list(
"Arms A+B" = c("A: Drug X", "B: Placebo"),
"Arms A+C" = c("A: Drug X", "C: Combination")
)
# Use of split_cols_by_groups without reference column.
basic_table() %>%
split_cols_by_groups("ARM", groups) %>%
add_colcounts() %>%
analyze("AGE") %>%
build_table(DM)
#> Arms A+B Arms A+C
#> (N=227) (N=250)
#> ——————————————————————————
#> Mean 34.03 34.73
# Including differentiated output in the reference column.
basic_table() %>%
split_cols_by_groups("ARM", groups_list = groups, ref_group = "Arms A+B") %>%
analyze(
"AGE",
afun = function(x, .ref_group, .in_ref_col) {
if (.in_ref_col) {
in_rows("Diff. of Averages" = rcell(NULL))
} else {
in_rows("Diff. of Averages" = rcell(mean(x) - mean(.ref_group), format = "xx.xx"))
}
}
) %>%
build_table(DM)
#> Arms A+B Arms A+C
#> ———————————————————————————————————————
#> Diff. of Averages 0.71
# 3 - Binary list dividing factor levels into reference and treatment
# `combine_groups` defines reference and treatment.
groups <- combine_groups(
fct = DM$ARM,
ref = c("A: Drug X", "B: Placebo")
)
groups
#> $`A: Drug X/B: Placebo`
#> [1] "A: Drug X" "B: Placebo"
#>
#> $`C: Combination`
#> [1] "C: Combination"
#>
# Use group definition without reference column.
basic_table() %>%
split_cols_by_groups("ARM", groups_list = groups) %>%
add_colcounts() %>%
analyze("AGE") %>%
build_table(DM)
#> A: Drug X/B: Placebo C: Combination
#> (N=227) (N=129)
#> ————————————————————————————————————————————
#> Mean 34.03 34.57
# Use group definition with reference column (first item of groups).
basic_table() %>%
split_cols_by_groups("ARM", groups, ref_group = names(groups)[1]) %>%
add_colcounts() %>%
analyze(
"AGE",
afun = function(x, .ref_group, .in_ref_col) {
if (.in_ref_col) {
in_rows("Diff Mean" = rcell(NULL))
} else {
in_rows("Diff Mean" = rcell(mean(x) - mean(.ref_group), format = "xx.xx"))
}
}
) %>%
build_table(DM)
#> A: Drug X/B: Placebo C: Combination
#> (N=227) (N=129)
#> —————————————————————————————————————————————————
#> Diff Mean 0.54