View source: R/datasummary_balance.R
datasummary_balance | R Documentation |
Creates balance tables with summary statistics for different subsets of the
data (e.g., control and treatment groups). It can also be used to create
summary tables for full data sets. See the Details and Examples sections
below, and the vignettes on the modelsummary
website:
https://modelsummary.com/
https://modelsummary.com/articles/datasummary.html
datasummary_balance(
formula,
data,
output = "default",
fmt = fmt_decimal(digits = 1, pdigits = 3),
title = NULL,
notes = NULL,
align = NULL,
stars = FALSE,
add_columns = NULL,
add_rows = NULL,
dinm = TRUE,
dinm_statistic = "std.error",
escape = TRUE,
...
)
formula |
a one-sided formula with the "condition" or "column" variable on the right-hand side. ~1 can be used to show summary statistics for the full data set |
data |
A data.frame (or tibble). If this data includes columns called
"blocks", "clusters", and/or "weights", the "estimatr" package will consider
them when calculating the difference in means. If there is a |
output |
filename or object type (character string)
|
fmt |
how to format numeric values: integer, user-supplied function, or
|
title |
string |
notes |
list or vector of notes to append to the bottom of the table. |
align |
A string with a number of characters equal to the number of columns in
the table (e.g.,
|
stars |
to indicate statistical significance
|
add_columns |
a data.frame (or tibble) with the same number of rows as your main table. |
add_rows |
a data.frame (or tibble) with the same number of columns as your main table. By default, rows are appended to the bottom of the table. You can define a "position" attribute of integers to set the row positions. See Examples section below. |
dinm |
TRUE calculates a difference in means with uncertainty
estimates. This option is only available if the |
dinm_statistic |
string: "std.error" or "p.value" |
escape |
boolean TRUE escapes or substitutes LaTeX/HTML characters which could prevent the file from compiling/displaying. This setting does not affect captions or notes. |
... |
all other arguments are passed through to the table-making
functions kableExtra::kbl, gt::gt, DT::datatable, etc. depending on the |
The behavior of modelsummary
can be modified by setting global options. For example:
options(modelsummary_model_labels = "roman")
The rest of this section describes each of the options above.
These global option changes the style of the default column headers:
options(modelsummary_model_labels = "roman")
options(modelsummary_panel_labels = "roman")
The supported styles are: "model", "panel", "arabic", "letters", "roman", "(arabic)", "(letters)", "(roman)""
The panel-specific option is only used when shape="rbind"
modelsummary
supports 4 table-making packages: kableExtra
, gt
,
flextable
, huxtable
, and DT
. Some of these packages have overlapping
functionalities. For example, 3 of those packages can export to LaTeX. 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_latex = 'gt')
options(modelsummary_factory_word = 'huxtable')
options(modelsummary_factory_png = 'gt')
Change the look of tables in an automated and replicable way, using the modelsummary
theming functionality. See the vignette: https://modelsummary.com/articles/appearance.html
modelsummary_theme_gt
modelsummary_theme_kableExtra
modelsummary_theme_huxtable
modelsummary_theme_flextable
modelsummary_theme_dataframe
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 = "broom")
options(modelsummary_get = "easystats")
options(modelsummary_get = "all")
By default, LaTeX tables enclose all numeric entries in the \num{}
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")
library(modelsummary) datasummary_balance(~am, mtcars)
Arel-Bundock V (2022). “modelsummary: Data and Model Summaries in R.” Journal of Statistical Software, 103(1), 1-23. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.18637/jss.v103.i01")}.'
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.