analyze_vars_in_cols {tern} | R Documentation |
Summarize numeric variables in columns
Description
Layout-creating function which can be used for creating column-wise summary tables.
This function sets the analysis methods as column labels and is a wrapper for
rtables::analyze_colvars()
. It was designed principally for PK tables.
Usage
analyze_vars_in_cols(
lyt,
vars,
...,
.stats = c("n", "mean", "sd", "se", "cv", "geom_cv"),
.labels = c(n = "n", mean = "Mean", sd = "SD", se = "SE", cv = "CV (%)", geom_cv =
"CV % Geometric Mean"),
row_labels = NULL,
do_summarize_row_groups = FALSE,
split_col_vars = TRUE,
imp_rule = NULL,
avalcat_var = "AVALCAT1",
cache = FALSE,
.indent_mods = NULL,
na_str = default_na_str(),
nested = TRUE,
.formats = NULL,
.aligns = NULL
)
Arguments
lyt |
( |
vars |
( |
... |
additional arguments for the lower level functions. |
.stats |
( |
.labels |
(named |
row_labels |
( |
do_summarize_row_groups |
( |
split_col_vars |
( |
imp_rule |
( |
avalcat_var |
( |
cache |
( |
.indent_mods |
(named |
na_str |
( |
nested |
( |
.formats |
(named |
.aligns |
( |
Value
A layout object suitable for passing to further layouting functions, or to rtables::build_table()
.
Adding this function to an rtable
layout will summarize the given variables, arrange the output
in columns, and add it to the table layout.
Note
This is an experimental implementation of rtables::summarize_row_groups()
and
rtables::analyze_colvars()
that may be subjected to changes as rtables
extends its
support to more complex analysis pipelines on the column space. For the same reasons,
we encourage to read the examples carefully and file issues for cases that differ from
them.
Here labelstr
behaves differently than usual. If it is not defined (default as NULL
),
row labels are assigned automatically to the split values in case of rtables::analyze_colvars
(do_summarize_row_groups = FALSE
, the default), and to the group label for
do_summarize_row_groups = TRUE
.
See Also
analyze_vars()
, rtables::analyze_colvars()
.
Examples
library(dplyr)
# Data preparation
adpp <- tern_ex_adpp %>% h_pkparam_sort()
lyt <- basic_table() %>%
split_rows_by(var = "STRATA1", label_pos = "topleft") %>%
split_rows_by(
var = "SEX",
label_pos = "topleft",
child_labels = "hidden"
) %>% # Removes duplicated labels
analyze_vars_in_cols(vars = "AGE")
result <- build_table(lyt = lyt, df = adpp)
result
# By selecting just some statistics and ad-hoc labels
lyt <- basic_table() %>%
split_rows_by(var = "ARM", label_pos = "topleft") %>%
split_rows_by(
var = "SEX",
label_pos = "topleft",
child_labels = "hidden",
split_fun = drop_split_levels
) %>%
analyze_vars_in_cols(
vars = "AGE",
.stats = c("n", "cv", "geom_mean"),
.labels = c(
n = "aN",
cv = "aCV",
geom_mean = "aGeomMean"
)
)
result <- build_table(lyt = lyt, df = adpp)
result
# Changing row labels
lyt <- basic_table() %>%
analyze_vars_in_cols(
vars = "AGE",
row_labels = "some custom label"
)
result <- build_table(lyt, df = adpp)
result
# Pharmacokinetic parameters
lyt <- basic_table() %>%
split_rows_by(
var = "TLG_DISPLAY",
split_label = "PK Parameter",
label_pos = "topleft",
child_labels = "hidden"
) %>%
analyze_vars_in_cols(
vars = "AVAL"
)
result <- build_table(lyt, df = adpp)
result
# Multiple calls (summarize label and analyze underneath)
lyt <- basic_table() %>%
split_rows_by(
var = "TLG_DISPLAY",
split_label = "PK Parameter",
label_pos = "topleft"
) %>%
analyze_vars_in_cols(
vars = "AVAL",
do_summarize_row_groups = TRUE # does a summarize level
) %>%
split_rows_by("SEX",
child_labels = "hidden",
label_pos = "topleft"
) %>%
analyze_vars_in_cols(
vars = "AVAL",
split_col_vars = FALSE # avoids re-splitting the columns
)
result <- build_table(lyt, df = adpp)
result