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
h_count_cumulative(
x,
threshold,
lower_tail = TRUE,
include_eq = TRUE,
na.rm = TRUE,
.N_col
)
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.- threshold
(
number
)
a cutoff value as threshold to count values ofx
.- lower_tail
(
logical
)
whether to count lower tail, default isTRUE
.- include_eq
(
logical
)
whether to include value equal to thethreshold
in count, default isTRUE
.- na.rm
(
flag
)
whetherNA
values should be removed fromx
prior to analysis.- .N_col
(
count
)
denominator for fraction calculation.- thresholds
(
numeric
)
vector of cutoff value for the counts.- ...
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 for label.
- show_labels
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
A named vector of 2:
count
: the count of values less than, less or equal to, greater than, or greater or equal to a threshold of user specification.fraction
: the fraction of the count.
A named list:
count_fraction
: a list with eachthresholds
value as a component, each component contains a vector for the count and fraction.
a_count_cumulative()
returns the corresponding list with formatted rtables::CellValue()
.
Functions
h_count_cumulative()
: Helper function to calculate count and fraction ofx
values in the lower or upper tail given a threshold.s_count_cumulative()
: Statistics function that produces a named lists given a (numeric
) vector of thresholds.a_count_cumulative()
: Formatted Analysis function which can be further customized by callingrtables::make_afun()
on it. It is used asafun
inrtables::analyze()
.count_cumulative()
: Layout creating function which can be be used for creating summary tables for cumulative counts of a variable. The ellipsis (...
) conveys arguments tos_count_cumulative()
, for instancelower_tail = FALSE
if upper tail should be accounted for.
Examples
set.seed(1, kind = "Mersenne-Twister")
x <- c(sample(1:10, 10), NA)
.N_col <- length(x)
h_count_cumulative(x, 5, .N_col = .N_col)
#> count fraction
#> 5.0000000 0.4545455
h_count_cumulative(x, 5, lower_tail = FALSE, include_eq = FALSE, na.rm = FALSE, .N_col = .N_col)
#> count fraction
#> 6.0000000 0.5454545
h_count_cumulative(x, 0, lower_tail = FALSE, .N_col = .N_col)
#> count fraction
#> 10.0000000 0.9090909
h_count_cumulative(x, 100, lower_tail = FALSE, .N_col = .N_col)
#> count fraction
#> 0 0
# Internal function - s_count_cumulative
if (FALSE) {
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)
}
library(scda)
ADSL <- synthetic_cdisc_data("latest")$adsl
basic_table() %>%
split_cols_by("ARM") %>%
add_colcounts() %>%
count_cumulative(
vars = "AGE",
thresholds = c(40, 60)
) %>%
build_table(ADSL)
#> A: Drug X B: Placebo C: Combination
#> (N=134) (N=134) (N=132)
#> ————————————————————————————————————————————————————
#> AGE
#> <= 40 113 (84.3%) 103 (76.9%) 106 (80.3%)
#> <= 60 134 (100%) 133 (99.3%) 130 (98.5%)