analyze_vars_in_cols {tern} | R Documentation |
Analyze numeric variables in columns
Description
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.
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()
andrtables::analyze_colvars()
that may be subjected to changes asrtables
extends its support to more complex analysis pipelines in the column space. We encourage users to read the examples carefully and file issues for different use cases.In this function,
labelstr
behaves atypically. Iflabelstr = NULL
(the default), row labels are assigned automatically as the split values ifdo_summarize_row_groups = FALSE
(the default), and as the group label ifdo_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