
Patient counts with abnormal range values by baseline status
Source:R/abnormal_by_baseline.R
abnormal_by_baseline.RdPrimary 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) we condition on baseline range result and count
patients in the numerator and denominator as follows:
-
Not <Abnormal>denom: the number of patients without abnormality at baseline (excluding those with missing baseline)num: the number of patients indenomwho also have at least one abnormality post-baseline
-
<Abnormal>denom: the number of patients with abnormality at baselinenum: the number of patients indenomwho also have at least one abnormality post-baseline
-
Totaldenom: the number of patients with at least one valid measurement post-baselinenum: the number of patients indenomwho also have at least one abnormality post-baseline
Usage
count_abnormal_by_baseline(
lyt,
var,
abnormal,
variables = list(id = "USUBJID", baseline = "BNRIND"),
na_str = "<Missing>",
nested = TRUE,
...,
table_names = abnormal,
.stats = NULL,
.formats = NULL,
.labels = NULL,
.indent_mods = NULL
)
s_count_abnormal_by_baseline(
df,
.var,
abnormal,
na_str = "<Missing>",
variables = list(id = "USUBJID", baseline = "BNRIND")
)
a_count_abnormal_by_baseline(
df,
.var,
abnormal,
na_str = "<Missing>",
variables = list(id = "USUBJID", baseline = "BNRIND")
)Arguments
- lyt
(
PreDataTableLayouts)
layout that analyses will be added to.- abnormal
(
character)
values identifying the abnormal range level(s) in.var.- variables
(named
listofstring)
list of additional analysis variables.- na_str
(
string)
the explicitna_levelargument you used in the pre-processing steps (maybe withdf_explicit_na()). The default is"<Missing>".- nested
(
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.- ...
additional arguments for the lower level functions.
- table_names
(
character)
this can be customized in the case that the samevarsare analyzed multiple times, to avoid warnings fromrtables.- .stats
(
character)
statistics to select for the table. Runget_stats("abnormal_by_baseline")to see available statistics for this function.- .formats
(named
characterorlist)
formats for the statistics. See Details inanalyze_varsfor more information on the"auto"setting.- .labels
(named
character)
labels for the statistics (without indent).- .indent_mods
(named
integer)
indent modifiers for the labels. Defaults to 0, which corresponds to the unmodified default behavior. Can be negative.- df
(
data.frame)
data set containing all analysis variables.- .var, var
(
string)
single variable name that is passed byrtableswhen requested by a statistics function.
Value
count_abnormal_by_baseline()returns a layout object suitable for passing to further layouting functions, or tortables::build_table(). Adding this function to anrtablelayout will add formatted rows containing the statistics froms_count_abnormal_by_baseline()to the table layout.
s_count_abnormal_by_baseline()returns statisticfractionwhich is a named list with 3 labeled elements:not_abnormal,abnormal, andtotal. Each element contains a vector withnumanddenompatient counts.
a_count_abnormal_by_baseline()returns the corresponding list with formattedrtables::CellValue().
Functions
count_abnormal_by_baseline(): Layout-creating function which can take statistics function arguments and additional format arguments. This function is a wrapper forrtables::analyze().s_count_abnormal_by_baseline(): Statistics function for a singleabnormallevel.a_count_abnormal_by_baseline(): Formatted analysis function which is used asafunincount_abnormal_by_baseline().
Note
dfshould be filtered to include only post-baseline records.If the baseline variable or analysis variable contains
NA, it is expected thatNAhas been conveyed tona_levelappropriately beforehand withdf_explicit_na()orexplicit_na().
See also
Relevant description function d_count_abnormal_by_baseline().
Examples
df <- data.frame(
USUBJID = as.character(c(1:6)),
ANRIND = factor(c(rep("LOW", 4), "NORMAL", "HIGH")),
BNRIND = factor(c("LOW", "NORMAL", "HIGH", NA, "LOW", "NORMAL"))
)
df <- df_explicit_na(df)
# Layout creating function.
basic_table() %>%
count_abnormal_by_baseline(var = "ANRIND", abnormal = c(High = "HIGH")) %>%
build_table(df)
#> all obs
#> ————————————————————————
#> High
#> Not high 1/4 (25%)
#> High 0/1
#> Total 1/6 (16.7%)
# Passing of statistics function and formatting arguments.
df2 <- data.frame(
ID = as.character(c(1, 2, 3, 4)),
RANGE = factor(c("NORMAL", "LOW", "HIGH", "HIGH")),
BLRANGE = factor(c("LOW", "HIGH", "HIGH", "NORMAL"))
)
basic_table() %>%
count_abnormal_by_baseline(
var = "RANGE",
abnormal = c(Low = "LOW"),
variables = list(id = "ID", baseline = "BLRANGE"),
.formats = c(fraction = "xx / xx"),
.indent_mods = c(fraction = 2L)
) %>%
build_table(df2)
#> all obs
#> ———————————————————————
#> Low
#> Not low 1 / 3
#> Low 0 / 1
#> Total 1 / 4