View source: R/ard_tabulate_value.R
| ard_tabulate_value | R Documentation |
Tabulate an Analysis Results Data (ARD) for dichotomous or a specified value.
ard_tabulate_value(data, ...)
## S3 method for class 'data.frame'
ard_tabulate_value(
data,
variables,
by = dplyr::group_vars(data),
strata = NULL,
value = maximum_variable_value(data[variables]),
statistic = everything() ~ c("n", "N", "p"),
denominator = NULL,
fmt_fun = NULL,
stat_label = everything() ~ default_stat_labels(),
fmt_fn = deprecated(),
...
)
data |
( |
... |
Arguments passed to methods. |
variables |
( |
by, strata |
(
Arguments may be used in conjunction with one another. |
value |
(named |
statistic |
( |
denominator |
( |
fmt_fun |
( |
stat_label |
( |
fmt_fn |
an ARD data frame of class 'card'
By default, the ard_tabulate() 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 calculation for the
proportion is 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 string: one of "column", "row", or "cell".
"column", the default, returns percentages where the sum is equal to
one within the variable after the data frame has been subset with by/strata.
"row" gives 'row' percentages where by/strata columns are the 'top'
of a cross table, and the variables are the rows. This is well-defined
for a single by or strata variable, and care must be taken when there
are more to ensure the the results are as you expect.
"cell" gives percentages where the denominator is the number of non-missing
rows in the source data frame.
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 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.
When the p statistic is returned, the proportion is returned—bounded by [0, 1].
The default function to format the statistic scales the proportion by 100
and the percentage is returned which matches the default statistic label of '%'.
To get the formatted values, pass the ARD to apply_fmt_fun().
ard_tabulate_value(mtcars, by = vs, variables = c(cyl, am), value = list(cyl = 4))
mtcars |>
dplyr::group_by(vs) |>
ard_tabulate_value(
variables = c(cyl, am),
value = list(cyl = 4),
statistic = ~"p"
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.