Description
datasummary
can use any summary function which produces one numeric or character value per variable. The examples section of this documentation shows how to define custom summary functions.
modelsummary
also supplies several shortcut summary functions which can be used in datasummary()
formulas: Min, Max, Mean, Median, Var, SD, NPercent, NUnique, Ncol, P0, P25, P50, P75, P100.
See the Details and Examples sections below, and the vignettes on the modelsummary
website:
Usage
datasummary(
formula,
data,
output = getOption("modelsummary_output", default = "default"),
fmt = 2,
title = getOption("modelsummary_title", default = NULL),
notes = getOption("modelsummary_notes", default = NULL),
align = getOption("modelsummary_align", default = NULL),
add_columns = getOption("modelsummary_add_columns", default = NULL),
add_rows = getOption("modelsummary_add_rows", default = NULL),
sparse_header = getOption("modelsummary_sparse_header", default = TRUE),
escape = getOption("modelsummary_escape", default = TRUE),
...
)
Details
Visit the ‘modelsummary’ website for more usage examples: https://modelsummary.com
The ‘datasummary’ function is a thin wrapper around the ‘tabular’ function from the ‘tables’ package. More details about table-making formulas can be found in the ‘tables’ package documentation: ?tables::tabular
Hierarchical or "nested" column labels are only available for these output formats: tinytable, kableExtra, gt, html, rtf, and LaTeX. When saving tables to other formats, nested labels will be combined to a "flat" header.
Global Options
The behavior of modelsummary
can be modified by setting global options. In particular, most of the arguments for most of the package’s functions cna be set using global options. For example:
-
options(modelsummary_output = “modelsummary_list”)
-
options(modelsummary_statistic = ‘({conf.low}, {conf.high})’)
-
options(modelsummary_stars = TRUE)
Options not specific to given arguments are listed below.
Model labels: default column names
These global option changes the style of the default column headers:
The supported styles are: "model", "arabic", "letters", "roman", "(arabic)", "(letters)", "(roman)"
Table-making packages
modelsummary
supports 6 table-making packages: tinytable
, kableExtra
, gt
, flextable
, huxtable
, and DT
. Some of these packages have overlapping functionalities. To change the default backend used for a specific file format, you can use ’ the options
function:
options(modelsummary_factory_html = ‘kableExtra’)
options(modelsummary_factory_word = ‘huxtable’)
options(modelsummary_factory_png = ‘gt’)
options(modelsummary_factory_latex = ‘gt’)
options(modelsummary_factory_latex_tabular = ‘kableExtra’)
Table themes
Change the look of tables in an automated and replicable way, using the modelsummary
theming functionality. See the vignette: https://modelsummary.com/vignettes/appearance.html
-
modelsummary_theme_gt
-
modelsummary_theme_kableExtra
-
modelsummary_theme_huxtable
-
modelsummary_theme_flextable
-
modelsummary_theme_dataframe
Model extraction functions
modelsummary
can use two sets of packages to extract information from statistical models: the easystats
family (performance
and parameters
) and broom
. By default, it uses easystats
first and then falls back on broom
in case of failure. You can change the order of priorities or include goodness-of-fit extracted by both packages by setting:
options(modelsummary_get = “easystats”)
options(modelsummary_get = “broom”)
options(modelsummary_get = “all”)
The "all" option (default) means easystats then broom.
Formatting numeric entries
By default, LaTeX tables enclose all numeric entries in the
command from the siunitx package. To prevent this behavior, or to enclose numbers in dollar signs (for LaTeX math mode), users can call:
options(modelsummary_format_numeric_latex = “plain”)
options(modelsummary_format_numeric_latex = “mathmode”)
A similar option can be used to display numerical entries using MathJax in HTML tables:
options(modelsummary_format_numeric_html = “mathjax”)