Summarize cumulative counts of a (numeric
) vector that is less than, less or equal to,
greater than, or greater or equal to user-specific thresholds.
Usage
s_count_cumulative(
x,
thresholds,
lower_tail = TRUE,
include_eq = TRUE,
.N_col,
...
)
a_count_cumulative(
x,
thresholds,
lower_tail = TRUE,
include_eq = TRUE,
.N_col,
...
)
count_cumulative(
lyt,
vars,
var_labels = vars,
show_labels = "visible",
...,
table_names = vars,
.stats = NULL,
.formats = NULL,
.labels = NULL,
.indent_mods = NULL
)
Arguments
- x
(
numeric
)
vector of numbers we want to analyze.- thresholds
(
numeric
)
vector of cutoff value for the counts.- lower_tail
(
logical
)
whether to count lower tail, default isTRUE
.- include_eq
(
logical
)
whether to include value equal to thethreshold
in count, default isTRUE
.- .N_col
(
count
)
denominator for fraction calculation.- ...
additional arguments for the lower level functions.
- lyt
(
layout
)
input layout where analyses will be added to.- vars
(
character
)
variable names for the primary analysis variable to be iterated over.- var_labels
(
character
)
character for label.- show_labels
(
string
)
label visibility: one of "default", "visible" and "hidden".- table_names
(
character
)
this can be customized in case that the samevars
are analyzed multiple times, to avoid warnings fromrtables
.- .stats
(
character
)
statistics to select for the table.- .formats
(named
character
orlist
)
formats for the statistics.- .labels
(named
character
)
labels for the statistics (without indent).- .indent_mods
(named
integer
)
indent modifiers for the labels.
Value
s_count_cumulative()
returns a named list ofcount_fraction
s: a list with eachthresholds
value as a component, each component containing a vector for the count and fraction.
a_count_cumulative()
returns the corresponding list with formattedrtables::CellValue()
.
count_cumulative()
returns a layout object suitable for passing to further layouting functions, or tortables::build_table()
. Adding this function to anrtable
layout will add formatted rows containing the statistics froms_count_cumulative()
to the table layout.
Functions
s_count_cumulative()
: Statistics function that produces a named list given a numeric vector of thresholds.a_count_cumulative()
: Formatted analysis function which is used asafun
incount_cumulative()
.count_cumulative()
: Layout-creating function which can take statistics function arguments and additional format arguments. This function is a wrapper forrtables::analyze()
.
See also
Relevant helper function h_count_cumulative()
, and descriptive function d_count_cumulative()
.
Examples
# Internal function - s_count_cumulative
if (FALSE) {
set.seed(1, kind = "Mersenne-Twister")
x <- c(sample(1:10, 10), NA)
.N_col <- length(x)
s_count_cumulative(x, thresholds = c(0, 5, 11), .N_col = .N_col)
s_count_cumulative(x, thresholds = c(0, 5, 11), include_eq = FALSE, na.rm = FALSE, .N_col = .N_col)
}
# Internal function - a_count_cumulative
if (FALSE) {
# Use the Formatted Analysis function for `analyze()`. We need to ungroup `count_fraction` first
# so that the `rtables` formatting function `format_count_fraction()` can be applied correctly.
afun <- make_afun(a_count_cumulative, .ungroup_stats = "count_fraction")
afun(x, thresholds = c(0, 5, 11), .N_col = .N_col)
}
basic_table() %>%
split_cols_by("ARM") %>%
add_colcounts() %>%
count_cumulative(
vars = "AGE",
thresholds = c(40, 60)
) %>%
build_table(tern_ex_adsl)
#> A: Drug X B: Placebo C: Combination
#> (N=69) (N=73) (N=58)
#> ——————————————————————————————————————————————————
#> AGE
#> <= 40 52 (75.4%) 58 (79.5%) 41 (70.7%)
#> <= 60 69 (100%) 73 (100%) 58 (100%)