Skip to contents

This function returns a table of descriptive statistics generated by some tbl_fn function. Additionally, statistics can be computed separately by groups. Groups can also be compared using some ana_fn function.

Usage

get_desc_table(df, vars, tbl_fn, group = NULL, ana_fn = NULL, ...)

Arguments

df

data.frame

vars

Vector of variable names

tbl_fn

Function that generates table

group

Name of grouping variable

ana_fn

Function that computes p-values (or other statistics to compare groups)

...

Additional named arguments passed to ana_fn

Value

Table of descriptive statistics

Details

For numeric variables, a natural choice is to use tbl_fn=tbl_fn_num(), while for categorical variables, use tbl_fn=tbl_fn_fac(). Alternatively, custom functions can be specified.

If group is specified, you have the option of requesting p-values (or some other statistic) comparing groups. For numeric variables, a natural choice is ana_fn=ana_fn_aov(), which computes p-values using analysis of variance. For factor variables, p-values can be obtained with Chi-square tests using ana_fn=ana_fn_chisq().

Examples

if (FALSE) {
# numeric variables
df |> get_desc_table(
    vars=c("age", "score"),
    tbl_fn=tbl_fn_num,
    group="TreatmentGroup",
    ana_fn=ana_fn_aov
)

# factor variables
df |> get_desc_table(
    vars=c("Nationality", "Diagnostic"),
    tbl_fn=tbl_fn_fac,
    group="TreatmentGroup",
    ana_fn=ana_fn_chisq
)
}