The layout-creating function analyze_vars_in_cols()
creates a layout element to generate a column-wise
analysis table.
This function sets the analysis methods as column labels and is a wrapper for rtables::analyze_colvars()
.
It was designed principally for PK tables.
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
)
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.
(PreDataTableLayouts
)
layout that analyses will be added to.
(character
)
variable names for the primary analysis variable to be iterated over.
additional arguments for the lower level functions.
(character
)
statistics to select for the table.
(named character
)
labels for the statistics (without indent).
(character
)
as this function works in columns space, usually .labels
character vector applies on the column space. You can change the row labels by defining this
parameter to a named character vector with names corresponding to the split values. It defaults
to NULL
and if it contains only one string
, it will duplicate that as a row label.
(flag
)
defaults to FALSE
and applies the analysis to the current
label rows. This is a wrapper of rtables::summarize_row_groups()
and it can accept labelstr
to define row labels. This behavior is not supported as we never need to overload row labels.
(flag
)
defaults to TRUE
and puts the analysis results onto the columns.
This option allows you to add multiple instances of this functions, also in a nested fashion,
without adding more splits. This split must happen only one time on a single layout.
(string
or NULL
)
imputation rule setting. Defaults to NULL
for no imputation rule. Can
also be "1/3"
to implement 1/3 imputation rule or "1/2"
to implement 1/2 imputation rule. In order
to use an imputation rule, the avalcat_var
argument must be specified. See imputation_rule()
for more details on imputation.
(string
)
if imp_rule
is not NULL
, name of variable that indicates whether a
row in the data corresponds to an analysis value in category "BLQ"
, "LTR"
, "<PCLLOQ"
, or none of
the above (defaults to "AVALCAT1"
). Variable must be present in the data and should match the variable
used to calculate the n_blq
statistic (if included in .stats
).
(flag
)
whether to store computed values in a temporary caching environment. This will
speed up calculations in large tables, but should be set to FALSE
if the same rtable
layout is
used for multiple tables with different data. Defaults to FALSE
.
(named integer
)
indent modifiers for the labels. Defaults to 0, which corresponds to the
unmodified default behavior. Can be negative.
(string
)
string used to replace all NA
or empty values in the output.
(flag
)
whether this layout instruction should be applied within the existing layout structure _if
possible (TRUE
, the default) or as a new top-level element (FALSE
). Ignored if it would nest a split.
underneath analyses, which is not allowed.
(named character
or list
)
formats for the statistics. See Details in analyze_vars
for more
information on the "auto"
setting.
(character
or NULL
)
alignment for table contents (not including labels). When NULL
,
"center"
is applied. See formatters::list_valid_aligns()
for a list of all currently supported alignments.
analyze_vars()
, rtables::analyze_colvars()
.
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
Run the code above in your browser using DataLab