The tbl_ard_summary()
function tables descriptive statistics for
continuous, categorical, and dichotomous variables.
The functions accepts an ARD object.
Usage
tbl_ard_summary(
cards,
by = NULL,
statistic = list(all_continuous() ~ "{median} ({p25}, {p75})", all_categorical() ~
"{n} ({p}%)"),
type = NULL,
label = NULL,
missing = c("no", "ifany", "always"),
missing_text = "Unknown",
missing_stat = "{N_miss}",
include = everything(),
overall = FALSE
)
Arguments
- cards
(
card
)
An ARD object of class"card"
typically created withcards::ard_*()
functions.- by
(
tidy-select
)
A single column fromdata
. Summary statistics will be stratified by this variable. Default isNULL
- statistic
(
formula-list-selector
)
Used to specify the summary statistics for each variable. Each of the statistics must be present incard
as no new statistics are calculated in this function. The default islist(all_continuous() ~ "{median} ({p25}, {p75})", all_categorical() ~ "{n} ({p}%)")
.- type
(
formula-list-selector
)
Specifies the summary type. Accepted value arec("continuous", "continuous2", "categorical", "dichotomous")
. Continuous summaries may be assignedc("continuous", "continuous2")
, while categorical and dichotomous cannot be modified.- label
(
formula-list-selector
)
Used to override default labels in summary table, e.g.list(age = "Age, years")
. The default for each variable is the column label attribute,attr(., 'label')
. If no label has been set, the column name is used.- missing, missing_text, missing_stat
Arguments dictating how and if missing values are presented:
missing
: must be one ofc("no", "ifany", "always")
missing_text
: string indicating text shown on missing row. Default is"Unknown"
missing_stat
: statistic to show on missing row. Default is"{N_miss}"
. Possible values areN_miss
,N_obs
,N_nonmiss
,p_miss
,p_nonmiss
- include
(
tidy-select
)
Variables to include in the summary table. Default iseverything()
- overall
(scalar
logical
)
WhenTRUE
, thecards
input is parsed into two parts to runtbl_ard_summary(cards_by) |> add_overall(cards_overall)
. Can only by used whenby
argument is specified. Default isFALSE
.
Details
There are three types of additional data that can be included in the ARD to improve the default appearance of the table.
Attributes: When attributes are included, the default labels will be the variable labels, when available. Attributes can be included in an ARD with
cards::ard_attributes()
orard_stack(.attributes = TRUE)
.Missing: When missing results are included, users can include missing counts or rates for variables with
tbl_ard_summary(missing = c("ifany", "always"))
. The missing statistics can be included in an ARD withcards::ard_missing()
orard_stack(.missing = TRUE)
.Total N: The total N is saved internally when available, and it can be calculated with
cards::ard_total_n()
orard_stack(.total_n = TRUE)
.
Examples
library(cards)
ard_stack(
data = ADSL,
ard_categorical(variables = "AGEGR1"),
ard_continuous(variables = "AGE"),
.attributes = TRUE,
.missing = TRUE,
.total_n = TRUE
) |>
tbl_ard_summary()
Characteristic
Overall1
1 n (%); Median (Q1, Q3)
ard_stack(
data = ADSL,
.by = ARM,
ard_categorical(variables = "AGEGR1"),
ard_continuous(variables = "AGE"),
.attributes = TRUE,
.missing = TRUE,
.total_n = TRUE
) |>
tbl_ard_summary(by = ARM)
Characteristic
Placebo1
Xanomeline High Dose1
Xanomeline Low Dose1
1 n (%); Median (Q1, Q3)
ard_stack(
data = ADSL,
.by = ARM,
ard_categorical(variables = "AGEGR1"),
ard_continuous(variables = "AGE"),
.attributes = TRUE,
.missing = TRUE,
.total_n = TRUE,
.overall = TRUE
) |>
tbl_ard_summary(by = ARM, overall = TRUE)
Characteristic
Overall1
Placebo1
Xanomeline High Dose1
Xanomeline Low Dose1
1 n (%); Median (Q1, Q3)