Patient Counts with Abnormal Range Values by Baseline Status
Source:R/abnormal_by_baseline.R
abnormal_by_baseline.Rd
Usage
d_count_abnormal_by_baseline(abnormal)
s_count_abnormal_by_baseline(
df,
.var,
abnormal,
na_level = "<Missing>",
variables = list(id = "USUBJID", baseline = "BNRIND")
)
a_count_abnormal_by_baseline(
df,
.var,
abnormal,
na_level = "<Missing>",
variables = list(id = "USUBJID", baseline = "BNRIND")
)
count_abnormal_by_baseline(
lyt,
var,
abnormal,
...,
table_names = abnormal,
.stats = NULL,
.formats = NULL,
.labels = NULL,
.indent_mods = NULL
)
Arguments
- abnormal
(
character
)
identifying the abnormal range level(s) in.var
.- df
(
data frame
)
data set containing all analysis variables.- .var, var
(
string
)
single variable name that is passed byrtables
when requested by a statistics function.- na_level
(
string
)
the explicitna_level
argument you used in the pre-processing steps (maybe withdf_explicit_na()
). The default is"<Missing>"
.- variables
(named
list
ofstring
)
list of additional analysis variables.- 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 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_count_abnormal_by_baseline()
returns the corresponding list with formatted rtables::CellValue()
.
Details
Note that df
should be filtered to include only post-baseline records.
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) 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 indenom
who also have at least one abnormality post-baseline
-
<Abnormal>
denom
: the number of patients with abnormality at baselinenum
: the number of patients indenom
who also have at least one abnormality post-baseline
-
Total
denom
: the number of patients with at least one valid measurement post-baselinenum
: the number of patients indenom
who also have at least one abnormality post-baseline
Functions
d_count_abnormal_by_baseline()
: Description Function that produces the labels fors_count_abnormal_by_baseline()
.s_count_abnormal_by_baseline()
: For a singleabnormal
level, produce a statisticfraction
which is a named list with 3 elements:not_abnormal
,abnormal
andtotal
. Each element contains a vector withnum
anddenom
counts of patients. Please note that if the baseline variable or analysis variable containsNA
, it is expected thatNA
has been conveyed tona_level
appropriately beforehand withdf_explicit_na()
orexplicit_na()
.a_count_abnormal_by_baseline()
: Formatted Analysis function which can be further customized by callingrtables::make_afun()
on it. It is used asafun
inrtables::analyze()
.count_abnormal_by_baseline()
: Layout creating function which can be used for creating tables, which can take statistics function arguments and additional format arguments (see below).
Examples
d_count_abnormal_by_baseline("LOW")
#> $not_abnormal
#> [1] "Not low baseline status"
#>
#> $abnormal
#> [1] "Low baseline status"
#>
#> $total
#> [1] "Total"
#>
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)
# Internal function - s_count_abnormal_by_baseline
if (FALSE) {
# Just for one abnormal level.
s_count_abnormal_by_baseline(df, .var = "ANRIND", abnormal = "HIGH")
}
# Internal function - a_count_abnormal_by_baseline
if (FALSE) {
# Use the Formatted Analysis function for `analyze()`. We need to ungroup `fraction` first
# so that the `rtables` formatting function `format_fraction()` can be applied correctly.
afun <- make_afun(a_count_abnormal_by_baseline, .ungroup_stats = "fraction")
afun(df, .var = "ANRIND", abnormal = "LOW")
}
# Layout creating function.
basic_table() %>%
count_abnormal_by_baseline(var = "ANRIND", abnormal = c(High = "HIGH")) %>%
build_table(df)
#> all obs
#> ————————————————————————————————————————
#> High
#> Not high baseline status 1/4 (25%)
#> High baseline status 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 baseline status 1 / 3
#> Low baseline status 0 / 1
#> Total 1 / 4