This function creates descriptive tables for variables in a dataset. It can handle qualitative and quantitative variables, grouped or ungrouped, and supports multiple configurations for handling missing data (DM).
desc_var(
data1,
table_title = "",
quali = NULL,
quanti = NULL,
add_total = TRUE,
var_title = "Variable",
by_group = FALSE,
var_group = NULL,
group_title = NULL,
digits = list(mean_sd = 1, median_q1_q3_min_max = 1, pct = 1),
drop_levels = TRUE,
freq_relevel = FALSE,
tests = FALSE,
show_n_per_group = FALSE,
show_missing_data = NULL,
var_tot = NULL,
var_characteristic = NULL
)A data frame containing the dataset to be analyzed.
A character string specifying the title of the table.
A vector of qualitative variables to be described. Defaults to NULL.
A vector of quantitative variables to be described. Defaults to NULL.
A boolean (default is TRUE) to add total column or not when var_group is specified.
A character string for the title of the variable column in the table. Defaults to "Variable".
A boolean (default is FALSE) to analyse by group.
A variable used for grouping (if applicable). Defaults to NULL.
A character string specifying the title for the grouping variable. Default is NULL and get the label or the variable.
A list, the number of decimal places to round categorical and continuous variable. Default is list(mean_sd = 1, median_q1_q3_min_max = 1, pct = 1).
Boolean (default = TRUE). Drop unused levels.
Boolean (default = FALSE). Reorder factors by frequency.
A value in order to add p value. Default to FALSE OPTION :
FALSE: No p-value add
TRUE: Add p-value made by default by gtsummary. See gtsummary add_p() options.
list(): To force tests. See gtsummary add_p() options.
Default to FALSE. Should the 'N' appears in the column header of the groups. Can be either :
FALSE: No 'N' is shown
TRUE: 'N' is shown
Default to NULL. Should the missing data be displayed. Can be either :
FALSE: No missing data displayed
TRUE: Missing data displayed
NULL (default): will be switch to anyNA(data1) value.
A string specifying the name of total column. Default is NULL and will guess from theme_gtsummary_language().
A string specifying the name of characteristic column. Default is NULL and will guess from theme_gtsummary_language().
A gtsummary table object containing the descriptive statistics.
The function processes the dataset according to the specified parameters and generates descriptive tables.
It first uses the ajouter_label_ndm() function to append missing data statistics to variable labels.
Depending on the group and DM arguments, it adjusts the dataset and creates tables using helper functions like desc_group, desc_degroup, and desc_degroup_group.
Qualitative variables are reordered, and unused levels are dropped when necessary.