Primary analysis variable .var indicates the abnormal range result (character or factor)
and additional analysis variables are id (character or factor) and baseline (character or
factor). For each direction specified in abnormal (e.g. high or low) count patients in the
numerator and denominator as follows:
numthe number of patients with this abnormality recorded while on treatment.
denomthe number of patients with at least one post-baseline assessment.
Note, the denominator includes patients that might have other abnormal levels at baseline, and patients with missing baseline. Note, optionally patients with this abnormality at baseline can be excluded from numerator and denominator.
Usage
s_count_abnormal(
df,
.var,
abnormal = list(Low = "LOW", High = "HIGH"),
variables = list(id = "USUBJID", baseline = "BNRIND"),
exclude_base_abn = FALSE
)
a_count_abnormal(
df,
.var,
abnormal = list(Low = "LOW", High = "HIGH"),
variables = list(id = "USUBJID", baseline = "BNRIND"),
exclude_base_abn = FALSE
)
count_abnormal(
lyt,
var,
...,
table_names = var,
.stats = NULL,
.formats = NULL,
.labels = NULL,
.indent_mods = NULL
)Arguments
- df
(
data frame)
data set containing all analysis variables.- .var, var
(
string)
single variable name that is passed byrtableswhen requested by a statistics function.- abnormal
(
named list)
identifying the abnormal range level(s) invar. Default tolist(Low = "LOW", High = "HIGH")but you can also group different levels into the name list, for example,abnormal = list(Low = c("LOW", "LOW LOW"), High = c("HIGH", "HIGH HIGH"))- variables
(named
listofstring)
list of additional analysis variables.- exclude_base_abn
(
flag)
whether to exclude subjects with baseline abnormality from numerator and denominator.- lyt
(
layout)
input layout where analyses will be added to.- ...
additional arguments for the lower level functions.
- table_names
(
character)
this can be customized in case that the samevarsare analyzed multiple times, to avoid warnings fromrtables.- .stats
(
character)
statistics to select for the table.- .formats
(named
characterorlist)
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_abnormal() returns the statistic fraction which is a
vector with num and denom counts of patients.
a_count_abnormal() returns the corresponding list with formatted rtables::CellValue().
count_abnormal() can be used with multiple abnormal levels and modifies the layout.
Functions
s_count_abnormal(): Statistics function which counts patients with abnormal range values for a singleabnormallevel.a_count_abnormal(): Formatted Analysis function which can be further customized by callingrtables::make_afun()on it. It is used asafuninrtables::analyze().count_abnormal(): Layout creating function which can be used for creating tables, which can take statistics function arguments and additional format arguments (see below). Note that it only works with a single variable but multiple abnormal levels.
Examples
library(dplyr)
#>
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#>
#> filter, lag
#> The following objects are masked from ‘package:base’:
#>
#> intersect, setdiff, setequal, union
df <- data.frame(
USUBJID = as.character(c(1, 1, 2, 2)),
ANRIND = factor(c("NORMAL", "LOW", "HIGH", "HIGH")),
BNRIND = factor(c("NORMAL", "NORMAL", "HIGH", "HIGH")),
ONTRTFL = c("", "Y", "", "Y"),
stringsAsFactors = FALSE
)
# Select only post-baseline records.
df <- df %>%
filter(ONTRTFL == "Y")
# Internal function - s_count_abnormal
if (FALSE) {
# For abnormal level "HIGH" we get the following counts.
s_count_abnormal(df, .var = "ANRIND", abnormal = list(high = "HIGH", low = "LOW"))
# Optionally exclude patients with abnormality at baseline.
s_count_abnormal(
df,
.var = "ANRIND",
abnormal = list(high = "HIGH", low = "LOW"),
exclude_base_abn = TRUE
)
}
# Internal function - a_count_abnormal
if (FALSE) {
# Use the Formatted Analysis function for `analyze()`.
a_fun <- make_afun(a_count_abnormal, .ungroup_stats = "fraction")
a_fun(df, .var = "ANRIND", abnormal = list(low = "LOW", high = "HIGH"))
}
# Layout creating function.
basic_table() %>%
count_abnormal(var = "ANRIND", abnormal = list(high = "HIGH", low = "LOW")) %>%
build_table(df)
#> all obs
#> ————————————————
#> high 1/2 (50%)
#> low 1/2 (50%)
# Passing of statistics function and formatting arguments.
df2 <- data.frame(
ID = as.character(c(1, 1, 2, 2)),
RANGE = factor(c("NORMAL", "LOW", "HIGH", "HIGH")),
BL_RANGE = factor(c("NORMAL", "NORMAL", "HIGH", "HIGH")),
ONTRTFL = c("", "Y", "", "Y"),
stringsAsFactors = FALSE
)
# Select only post-baseline records.
df2 <- df2 %>%
filter(ONTRTFL == "Y")
basic_table() %>%
count_abnormal(
var = "RANGE",
abnormal = list(low = "LOW", high = "HIGH"),
variables = list(id = "ID", baseline = "BL_RANGE")
) %>%
build_table(df2)
#> all obs
#> ————————————————
#> low 1/2 (50%)
#> high 1/2 (50%)