ard_categorical {cards} | R Documentation |
Categorical ARD Statistics
Description
Compute Analysis Results Data (ARD) for categorical summary statistics.
Usage
ard_categorical(data, ...)
## S3 method for class 'data.frame'
ard_categorical(
data,
variables,
by = dplyr::group_vars(data),
strata = NULL,
statistic = everything() ~ c("n", "p", "N"),
denominator = NULL,
fmt_fn = NULL,
stat_label = everything() ~ default_stat_labels(),
...
)
Arguments
data |
( |
... |
Arguments passed to methods. |
variables |
( |
by , strata |
(
Arguments may be used in conjunction with one another. |
statistic |
( |
denominator |
( |
fmt_fn |
( |
stat_label |
( |
Value
an ARD data frame of class 'card'
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.
Other Statistics
In some cases, you may need other kinds of statistics for categorical variables.
Despite the name, ard_continuous()
can be used to obtain these statistics.
In the example below, we calculate the mode of a categorical variable.
get_mode <- function(x) { table(x) |> sort(decreasing = TRUE) |> names() |> getElement(1L) } ADSL |> ard_continuous( variables = AGEGR1, statistic = list(AGEGR1 = list(mode = get_mode)) ) #> {cards} data frame: 1 x 8 #> variable context stat_name stat_label stat fmt_fn #> 1 AGEGR1 continuo… mode mode 65-80 <fn> #> i 2 more variables: warning, error
Examples
ard_categorical(ADSL, by = "ARM", variables = "AGEGR1")
ADSL |>
dplyr::group_by(ARM) |>
ard_categorical(
variables = "AGEGR1",
statistic = everything() ~ "n"
)