Learn R Programming

modelsummary (version 0.3.0)

msummary: Beautiful, customizable summaries of statistical models

Description

`msummary()` is a shortcut to `modelsummary()`

Usage

msummary(
  models,
  output = "default",
  fmt = "%.3f",
  statistic = "std.error",
  statistic_override = NULL,
  statistic_vertical = TRUE,
  conf_level = 0.95,
  stars = FALSE,
  coef_map = NULL,
  coef_omit = NULL,
  gof_map = modelsummary::gof_map,
  gof_omit = NULL,
  add_rows = NULL,
  add_rows_location = NULL,
  title = NULL,
  notes = NULL,
  filename = NULL,
  subtitle = NULL,
  ...
)

Arguments

models

a single model object or a (potentially named) list of models to summarize

output

filename or object type (string)

  • Supported filename extensions: .html, .tex, .md, .txt, .png, .jpg.

  • Supported object types: "gt", "html", "markdown", "latex". "gt" objects are created by the `gt` package; other object types are created by the `kableExtra` package.

  • When a file name is supplied to the `output` argument, the table is written immediately to file. If you want to customize your table by post-processing it with functions provided by the `gt` or `kableExtra` packages, you need to choose a different output format (e.g., "gt", "latex", "html", "markdown"), and you need to save the table after post-processing using the `gt::gtsave`, `kable::save_kable`, or `cat` functions.

fmt

string which specifies how numeric values will be rounded. This string is passed to the `sprintf` function. '%.3f' will keep 3 digits after the decimal point with trailing zero. '%.5f' will keep 5 digits. '%.3e' will use exponential notation. See `?sprintf` for more options.

statistic

string name of the statistic to include in parentheses

  • Typical values: "conf.int", "std.error", "statistic", "p.value"

  • Alternative values: any column name produced by `broom::tidy(model)`

statistic_override

manually override the uncertainy estimates. This argument accepts three types of input:

  • a function or list of functions of length(models) which produce variance-covariance matrices with row and column names equal to the names of your coefficient estimates. For example, `R` supplies the `vcov` function, and the `sandwich` package supplies `vcovHC`, `vcovHAC`, etc.

  • a list of length(models) variance-covariance matrices with row and column names equal to the names of your coefficient estimates.

  • a list of length(models) vectors with names equal to the names of your coefficient estimates. Numeric vectors are formatted according to `fmt` and placed in brackets, character vectors printed as given.

statistic_vertical

TRUE if statistics should be printed below estimates. FALSE if statistics should be printed beside estimates.

conf_level

confidence level to use for confidence intervals

stars

to indicate statistical significance

  • FALSE (default): no significance stars.

  • TRUE: *=.1, **=.05, ***=.01

  • Named numeric vector for custom stars such as `c('*' = .1, '+' = .05)`

coef_map

named character vector. Names refer to the original variable names. Values refer to the variable names that will appear in the table. Coefficients which are omitted from this vector will be omitted from the table. The table will be ordered in the same order as this vector.

coef_omit

string regular expression. Omits all matching coefficients from the table (using `stringr::str_detect`).

gof_map

data.frame with four columns: `raw`, `clean`, `fmt`, and `omit`. See `modelsummary::gof_map`

gof_omit

string regular expression. Omits all matching gof statistics from the table (using `stringr::str_detect`).

add_rows

list of character vectors, each of length equal to the number of models + 1.

add_rows_location

integer or NULL. custom rows will be added to the bottom of the table if this parameter is NULL, or after the position set by this integer.

title

string

notes

list of notes to append to the bottom of the table.

filename

This argument was deprecated in favor of the `output` argument.

subtitle

This argument is deprecated. Use `title` or the `tab_header` function from the `gt` package.

...

all other arguments are passed to the `tidy` method used to extract estimates from the model. For example, this allows users to set `exponentiate=TRUE` to exponentiate logistic regression coefficients.

Value

a 'gt' table object.

Examples

Run this code
# NOT RUN {
# load data and estimate models
data(trees)
models <- list()
models[['Bivariate']] <- lm(Girth ~ Height, data = trees)
models[['Multivariate']] <- lm(Girth ~ Height + Volume, data = trees)

# simple table
msummary(models)

# confidence intervals, p values, or t-stats instead of standard errors
msummary(models, statistic = 'conf.int', conf_level = 0.99)
msummary(models, statistic = 'p.value', conf_level = 0.99)
msummary(models, statistic = 'statistic', conf_level = 0.99)

# rename and re-order coefficients
msummary(models, coef_map = c('Volume' = 'Large', 'Height' = 'Tall'))

# titles 
msummary(models, title = 'This is the title')

# title with italicized text
msummary(models, title = gt::md('This is *the* title'))

# notes at the bottom of the table (here, the second note includes markdown bold characters)
msummary(models, notes = list('A first note', gt::md('A **bold** note')))

# modify list of GOF statistics and their format using the built-in
# 'gof_map' data frame as a starting point
gof_custom <- modelsummary::gof_map 
gof_custom$omit[gof_custom$raw == 'deviance'] <- FALSE 
gof_custom$fmt[gof_custom$raw == 'r.squared'] <- "%.5f" 
msummary(models, gof_map = gof_custom)
# }
# NOT RUN {

# }

Run the code above in your browser using DataLab