Learn R Programming

⚠️There's a newer version (2.4.0) of this package.Take me there.

modelsummary

modelsummary creates tables and plots to summarize statistical models and data in R.

The tables and plots produced by modelsummary are beautiful and highly customizable. They can be echoed to the R console or displayed in the RStudio Viewer. They can be saved to a wide variety of formats, including HTML, PDF, Text/Markdown, LaTeX, MS Word, RTF, JPG, and PNG. Tables can easily be embedded in dynamic documents with Rmarkdown, knitr, or Sweave. modelsummary supports hundreds of model types out-of-the-box. The look of your tables is infinitely customizable using external package such as kableExtra, gt, flextable, huxtable, or DT.

modelsummary includes two families of functions:

  1. Model Summary
    • modelsummary: Regression tables with side-by-side models.
    • modelplot: Coefficient plots.
  2. Data Summary
    • datasummary: Powerful tool to create (multi-level) cross-tabs and data summaries.
    • datasummary_crosstab: Cross-tabulations.
    • datasummary_balance: Balance tables with subgroup statistics and difference in means (aka "Table 1").
    • datasummary_correlation: Correlation tables.
    • datasummary_skim: Quick overview ("skim") of a dataset.
    • datasummary_df: Turn dataframes into nice tables with titles, notes, etc.

The modelsummary website hosts a ton of examples. Make sure you click on the links at the top of this page: https://vincentarelbundock.github.io/modelsummary

The following tables and plots were created using modelsummary, without any manual editing at all:

Why should I use modelsummary?

Here are a few benefits of modelsummary over some alternative packages:

Easy

modelsummary is very easy to use. This simple call often suffices:

library(modelsummary)

mod <- lm(y ~ x, dat)
modelsummary(mod)

The command above will automatically display a summary table in the Rstudio Viewer or in a web browser. All you need is one word to change the output format. For example, a text-only version of the table can be printed to the Console by typing:

modelsummary(mod, output = "markdown")

Tables in Microsoft Word and LaTeX formats can be saved to file by typing:

modelsummary(mod, output = "table.docx")
modelsummary(mod, output = "table.tex")

Flexible

Information: The package offers many intuitive and powerful utilities to customize the information reported in a summary table. You can rename, reorder, subset or omit parameter estimates; choose the set of goodness-of-fit statistics to include; display various “robust” standard errors or confidence intervals; add titles, footnotes, or source notes; insert stars or custom characters to indicate levels of statistical significance; or add rows with supplemental information about your models.

Appearance: Thanks to the gt, kableExtra, huxtable, flextable, and DT packages, the appearance of modelsummary tables is endlessly customizable. The appearance customization page shows tables with colored cells, weird text, spanning column labels, row groups, titles, source notes, footnotes, significance stars, and more. This only scratches the surface of possibilities.

Supported models: Thanks to the broom and parameters, modelsummary supports hundreds of statistical models out-of-the-box. Installing other packages can extend the capabilities further (e.g., broom.mixed). It is also very easy to add or customize your own models.

Output formats: modelsummary tables can be saved to HTML, LaTeX, Text/Markdown, Microsoft Word, Powerpoint, RTF, JPG, or PNG formats. They can also be inserted seamlessly in Rmarkdown documents to produce automated documents and reports in PDF, HTML, RTF, or Microsoft Word formats.

Dangerous

modelsummary is dangerous! It allows users to do stupid stuff like replacing their intercepts by squirrels.

Reliable

modelsummary is reliably dangerous! The package is developed using a suite of unit tests with about 95% coverage, so it (probably) won’t break.

Community

modelsummary does not try to do everything. Instead, it leverages the incredible work of the R community. By building on top of the broom and parameters packages, modelsummary already supports hundreds of model types out-of-the-box. modelsummary also supports five of the most popular table-building and customization packages: gt, kableExtra, huxtable, flextable, and DT packages. By using those packages, modelsummary allows users to produce beautiful, endlessly customizable tables in a wide variety of formats, including HTML, PDF, LaTeX, Markdown, and MS Word.

One benefit of this community-focused approach is that when external packages improve, modelsummary improves as well. Another benefit is that leveraging external packages allows modelsummary to have a massively simplified codebase (relative to other similar packages). This should improve long term code maintainability, and allow contributors to participate through GitHub.

Installation

You can install modelsummary from CRAN:

install.packages('modelsummary')

You can install the development version of modelsummary (and its dependency insight) from R-Universe:

install.packages(
    c("modelsummary", "insight", "performance", "parameters"),
    repos = c(
        "https://vincentarelbundock.r-universe.dev",
        "https://easystats.r-universe.dev"))

Restart R completely before moving on.

Getting started

There are a million ways to customize the tables and plots produced by modelsummary. In this Getting Started section we will only scratch the surface. For details, see the vignettes:

To begin, load the modelsummary package and download data from the Rdatasets archive:

library(modelsummary)

url <- 'https://vincentarelbundock.github.io/Rdatasets/csv/HistData/Guerry.csv'
dat <- read.csv(url) 
dat$Small <- dat$Pop1831 > median(dat$Pop1831)

Quick overview of the data:

datasummary_skim(dat)

Balance table (aka "Table 1") with differences in means by subgroups:

datasummary_balance(~Small, dat)

Correlation table:

datasummary_correlation(dat)

Two variables and two statistics, nested in subgroups:

datasummary(Literacy + Commerce ~ Small * (mean + sd), dat)

Estimate a linear model and display the results:

mod <- lm(Donations ~ Crime_prop, data = dat)

modelsummary(mod)

Estimate five regression models, display the results side-by-side, and save them to a Microsoft Word document:

models <- list(
  "OLS 1"     = lm(Donations ~ Literacy + Clergy, data = dat),
  "Poisson 1" = glm(Donations ~ Literacy + Commerce, family = poisson, data = dat),
  "OLS 2"     = lm(Crime_pers ~ Literacy + Clergy, data = dat),
  "Poisson 2" = glm(Crime_pers ~ Literacy + Commerce, family = poisson, data = dat),
  "OLS 3"     = lm(Crime_prop ~ Literacy + Clergy, data = dat)
)

modelsummary(models, output = "table.docx")

Alternative packages

There are several excellent alternatives to draw model summary tables in R:

Copy Link

Version

Install

install.packages('modelsummary')

Monthly Downloads

31,540

Version

1.3.0

License

GPL-3

Maintainer

Vincent Arel-Bundock

Last Published

January 5th, 2023

Functions in modelsummary (1.3.0)

SD

datasummary statistic shortcut
Var

datasummary statistic shortcut
datasummary_balance

Balance table: Summary statistics for different subsets of the data (e.g., control and treatment groups)
coef_rename

Rename model terms
datasummary_crosstab

Cross tabulations for categorical variables
datasummary

Summary tables using 2-sided formulae: crosstabs, frequencies, table 1s and more.
colLabels

Retrieve or modify the row or column labels.
datasummary_df

Draw a table from a data.frame
datasummary_correlation

Generate a correlation table for all numeric variables in your dataset.
datasummary_skim

Quick overview of numeric or categorical variables
dsummary

dsummary() is a shortcut to datasummary()
datasummary_correlation_format

Format the content of a correlation table
get_estimates

Extract model estimates in a tidy format.
escape_html

Escape problematic characters to allow display in HTML
fmt_decimal

Rounding with decimal digits in the fmt argument
fmt_significant

Rounding with significant digits in the fmt argument
fmt_sprintf

Rounding with the sprintf() function in the fmt argument
dvnames

Title models with their dependent variables
fmt_statistic

Rounding with decimal digits on a per-statistic basis in the fmt argument for modelsummary()
fmt_term

Rounding with decimal digits on a per-term basis in the fmt argument for modelsummary()
get_gof

Extract model gof A mostly internal function with some potential uses outside.
glance_custom_internal.lm

Avoid namespace conflict when we want to customize glance internally and still allow users to do the same with their own functions
get_vcov

Allow users to override uncertainty estimates
gof_map

Data.frame used to clean up and format goodness-of-fit statistics
get_gof_parameters

Extract goodness-of-fit statistics from a single model using the performance package
escape_string

Make sure LaTeX and HTML are safe to compile
glance_custom_internal.default

Avoid namespace conflict when we want to customize glance internally and still allow users to do the same with their own functions
glance_custom

Extract custom information from a model object and turn it into a tidy data.frame or tibble with a single row.
glance_custom_internal

Avoid namespace conflict when we want to customize glance internally and still allow users to do the same with their own functions
get_gof_broom

Extract goodness-of-fit statistics from a single model using the broom package or another package with package which supplies a method for the generics::glance generic.
escape_latex

Escape problematic characters to allow compilation in LaTeX
get_vcov.mlm

Allow users to override uncertainty estimates
modelsummary

Model Summary Tables
msummary

msummary() is a shortcut to modelsummary()
labelSubset

Add a label to a logical vector.
map_gof

Internal function to subset, rename and re-order gof statistics
map_estimates

rename and reorder estimates from a single model (before merging to collapse)
modelplot

Model Summary Plots with Estimates and Confidence Intervals
reexports

tidy generic
rowLabels

Retrieve or modify the row or column labels.
hush

Execute code silently
update_modelsummary

Update modelsummary and its dependencies
tidy_custom_internal.default

Avoid namespace conflict when we want to customize glance internally and still allow users to do the same with their own functions
tidy_custom_internal

Avoid namespace conflict when we want to customize glance internally and still allow users to do the same with their own functions
supported_models

List of model objects from which modelsummary can extract estimates and statistics
modelsummary_wide

Superseded function
tidy_custom

Extract custom information from a model object and turn it into a tidy data.frame or tibble
Heading

'Heading' pseudo-function
Mean

datasummary statistic shortcut
Max

datasummary statistic shortcut
Ncol

datasummary statistic shortcut
Factor

Use a variable as a factor to give rows in a table.
Arguments

'Arguments' pseudo-function
Format

Use a variable as a factor to give rows in a table.
All

Include all columns of a dataframe.
DropEmpty

'DropEmpty' pseudo-function
AllObs

Display all observations in a table.
P100

datasummary statistic shortcut
P25

datasummary statistic shortcut
P0

datasummary statistic shortcut
P50

datasummary statistic shortcut
Min

datasummary statistic shortcut
Median

datasummary statistic shortcut
NPercent

datasummary statistic shortcut
Percent

Pseudo-function to compute a statistic relative to a reference set.
NUnique

datasummary statistic shortcut
P75

datasummary statistic shortcut
Paste

Generate terms to paste values together in table.
N

datasummary statistic shortcut
Histogram

datasummary statistic shortcut
RowFactor

Use a variable as a factor to give rows in a table.
Multicolumn

Use a variable as a factor to give rows in a table.
RowNum

Display all observations in a table.
PlusMinus

Generate 'x +/- y' terms in table.
PercentMissing

datasummary statistic shortcut