Performs hierarchical or nested tabulations, e.g. tabulates AE terms nested within AE system organ class.
ard_hierarchical()
includes summaries for the last variable listed in thevariables
argument, nested within the other variables included.ard_hierarchical_count()
includes summaries for all variables listed in thevariables
argument each summary nested within the preceding variables, e.g.variables=c(AESOC, AETERM)
summarizesAETERM
nested inAESOC
, and also summarizes the counts ofAESOC
.
Usage
ard_hierarchical(data, ...)
ard_hierarchical_count(data, ...)
# S3 method for class 'data.frame'
ard_hierarchical(
data,
variables,
by = dplyr::group_vars(data),
statistic = everything() ~ c("n", "N", "p"),
denominator = NULL,
fmt_fn = NULL,
stat_label = everything() ~ default_stat_labels(),
id = NULL,
...
)
# S3 method for class 'data.frame'
ard_hierarchical_count(
data,
variables,
by = dplyr::group_vars(data),
fmt_fn = NULL,
stat_label = everything() ~ default_stat_labels(),
...
)
Arguments
- data
(
data.frame
)
a data frame- ...
Arguments passed to methods.
- variables
(
tidy-select
)
variables to perform the nested/hierarchical tabulations within.- by
(
tidy-select
)
variables to perform tabulations by. All combinations of the variables specified here appear in results. Default isdplyr::group_vars(data)
.- statistic
(
formula-list-selector
)
a named list, a list of formulas, or a single formula where the list element one or more ofc("n", "N", "p")
(or the RHS of a formula).- denominator
(
data.frame
,integer
)
Specify this optional argument to change the denominator, e.g. the"N"
statistic. Default isNULL
. See below for details.- fmt_fn
(
formula-list-selector
)
a named list, a list of formulas, or a single formula where the list element is a named list of functions (or the RHS of a formula), e.g.list(mpg = list(mean = \(x) round(x, digits = 2) |> as.character()))
.- stat_label
(
formula-list-selector
)
a named list, a list of formulas, or a single formula where the list element is either a named list or a list of formulas defining the statistic labels, e.g.everything() ~ list(n = "n", p = "pct")
oreverything() ~ list(n ~ "n", p ~ "pct")
.- id
((
tidy-select
)
) an optional argument used to assert there are no duplicates with in the column(s) passed here. For example, ifid=USUBJID
is passed, we will add a check there are no duplicates indata['USUBJID']
.
Denominators
By default, the ard_categorical()
function returns the statistics "n"
, "N"
, and
"p"
, where little "n"
are the counts for the variable levels, and big "N"
is
the number of non-missing observations. The default calculation for the
percentage is merely p = n/N
.
However, it is sometimes necessary to provide a different "N"
to use
as the denominator in this calculation. For example, in a calculation
of the rates of various observed adverse events, you may need to update the
denominator to the number of enrolled subjects.
In such cases, use the denominator
argument to specify a new definition
of "N"
, and subsequently "p"
.
The argument expects one of the following inputs:
a data frame. Any columns in the data frame that overlap with the
by
/strata
columns will be used to calculate the new"N"
.an integer. This single integer will be used as the new
"N"
a string: one of
"column"
,"row"
, or"cell"
."column"
is equivalent todenominator=NULL
."row"
gives 'row' percentages whereby
/strata
columns are the 'top' of a cross table, and the variables are the rows."cell"
gives percentages where the denominator is the number of non-missing rows in the source data frame.a structured data frame. The data frame will include columns from
by
/strata
. The last column must be named"...ard_N..."
. The integers in this column will be used as the updated"N"
in the calculations.
Examples
ard_hierarchical(
data = ADAE,
variables = c(AESOC, AETERM),
by = c(TRTA, AESEV),
denominator = ADSL |> dplyr::rename(TRTA = ARM)
)
#> {cards} data frame: 6534 x 15
#> group1 group1_level group2 group2_level group3 group3_level variable
#> 1 TRTA Placebo AESEV MILD AESOC GASTROIN… AETERM
#> 2 TRTA Placebo AESEV MILD AESOC GASTROIN… AETERM
#> 3 TRTA Placebo AESEV MILD AESOC GASTROIN… AETERM
#> 4 TRTA Xanomeli… AESEV MILD AESOC GASTROIN… AETERM
#> 5 TRTA Xanomeli… AESEV MILD AESOC GASTROIN… AETERM
#> 6 TRTA Xanomeli… AESEV MILD AESOC GASTROIN… AETERM
#> 7 TRTA Xanomeli… AESEV MILD AESOC GASTROIN… AETERM
#> 8 TRTA Xanomeli… AESEV MILD AESOC GASTROIN… AETERM
#> 9 TRTA Xanomeli… AESEV MILD AESOC GASTROIN… AETERM
#> 10 TRTA Placebo AESEV MODERATE AESOC GASTROIN… AETERM
#> variable_level stat_name stat_label stat
#> 1 ABDOMINA… n n 0
#> 2 ABDOMINA… N N 86
#> 3 ABDOMINA… p % 0
#> 4 ABDOMINA… n n 1
#> 5 ABDOMINA… N N 84
#> 6 ABDOMINA… p % 0.012
#> 7 ABDOMINA… n n 0
#> 8 ABDOMINA… N N 84
#> 9 ABDOMINA… p % 0
#> 10 ABDOMINA… n n 0
#> ℹ 6524 more rows
#> ℹ Use `print(n = ...)` to see more rows
#> ℹ 4 more variables: context, fmt_fn, warning, error
ard_hierarchical_count(
data = ADAE,
variables = c(AESOC, AETERM),
by = TRTA
)
#> {cards} data frame: 795 x 13
#> group1 group1_level group2 group2_level variable variable_level stat_name
#> 1 TRTA Placebo AESOC GASTROIN… AETERM ABDOMINA… n
#> 2 TRTA Xanomeli… AESOC GASTROIN… AETERM ABDOMINA… n
#> 3 TRTA Xanomeli… AESOC GASTROIN… AETERM ABDOMINA… n
#> 4 TRTA Placebo AESOC GASTROIN… AETERM ABDOMINA… n
#> 5 TRTA Xanomeli… AESOC GASTROIN… AETERM ABDOMINA… n
#> 6 TRTA Xanomeli… AESOC GASTROIN… AETERM ABDOMINA… n
#> 7 TRTA Placebo AESOC SURGICAL… AETERM ACROCHOR… n
#> 8 TRTA Xanomeli… AESOC SURGICAL… AETERM ACROCHOR… n
#> 9 TRTA Xanomeli… AESOC SURGICAL… AETERM ACROCHOR… n
#> 10 TRTA Placebo AESOC SKIN AND… AETERM ACTINIC … n
#> stat_label stat
#> 1 n 0
#> 2 n 1
#> 3 n 0
#> 4 n 1
#> 5 n 2
#> 6 n 3
#> 7 n 0
#> 8 n 1
#> 9 n 0
#> 10 n 0
#> ℹ 785 more rows
#> ℹ Use `print(n = ...)` to see more rows
#> ℹ 4 more variables: context, fmt_fn, warning, error