### Install modelsummary Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/vignettes/get_started.html Install the modelsummary package using the remotes package. This is the first step to using the package. ```r remotes::install_github("vincentarelbundock/modelsummary") ``` -------------------------------- ### Install modelsummary and dependencies from R-Universe Source: https://github.com/vincentarelbundock/modelsummary/blob/main/README.md Install the development version of modelsummary and its dependencies from R-Universe. Ensure to restart R after installation. ```r install.packages( c("modelsummary", "tinytable", "insight", "performance", "parameters"), repos = c( "https://vincentarelbundock.r-universe.dev", "https://easystats.r-universe.dev")) ``` -------------------------------- ### Install modelsummary from CRAN Source: https://github.com/vincentarelbundock/modelsummary/blob/main/README.md Install the modelsummary package from the Comprehensive R Archive Network (CRAN). ```r install.packages('modelsummary') ``` -------------------------------- ### Basic Model Summary Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/vignettes/appearance.html Generates a basic model summary. No specific setup or imports are required beyond having the 'modelsummary' package installed. ```r library(modelsummary) library(lme4) # Load example data data(sleepstudy) # Fit a linear mixed-effects model model <- lmer(Reaction ~ Days + (Days | Subject), data = sleepstudy) # Generate a basic model summary modelsummary(model) ``` -------------------------------- ### Install Development Versions Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/NEWS.html Use the update_modelsummary() function to easily install the development versions of modelsummary and its dependencies. This is primarily for developers or users reporting bugs. ```R update_modelsummary() ``` -------------------------------- ### Using Default gof_map as a Starting Point Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/vignettes/modelsummary.html Filter and select columns from the default `gof_map` to create a custom list for display. This is useful for starting with a predefined set of statistics and modifying it. ```R gof_map <- modelsummary::gof_map %>% dplyr::filter(!omit) %>% dplyr::select(-omit) %>% plyr::dlply(1, c) ``` -------------------------------- ### Set default table-making backend for HTML Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/man/datasummary_correlation.html Specify the default table-making package to use for generating HTML tables. 'kableExtra' is used in this example. ```R options(modelsummary_factory_html = ‘kableExtra’) ``` -------------------------------- ### Set default table-making backend for PNG Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/man/datasummary_correlation.html Specify the default table-making package to use for generating PNG images of tables. 'gt' is used in this example. ```R options(modelsummary_factory_png = ‘gt’) ``` -------------------------------- ### Set default table-making backend for Word Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/man/datasummary_correlation.html Specify the default table-making package to use for generating Word tables. 'huxtable' is used in this example. ```R options(modelsummary_factory_word = ‘huxtable’) ``` -------------------------------- ### Load Data and Estimate Models Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/vignettes/appearance.html Loads data from a URL and estimates five different statistical models. This setup is used for demonstrating table customization. ```R library(modelsummary) url <- "https://vincentarelbundock.github.io/Rdatasets/csv/HistData/Guerry.csv" dat <- read.csv(url, na.strings = "") models <- list( I = lm(Donations ~ Literacy, data = dat), II = lm(Crime_pers ~ Literacy, data = dat), III = lm(Crime_prop ~ Literacy + Clergy, data = dat), IV = glm(Crime_pers ~ Literacy + Clergy, family = poisson, data = dat), V = glm(Donations ~ Literacy + Clergy, family = poisson, data = dat) ) ``` -------------------------------- ### Set default table-making backend for LaTeX Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/man/datasummary_correlation.html Specify the default table-making package to use for generating LaTeX tables. 'gt' is used in this example. ```R options(modelsummary_factory_latex = ‘gt’) ``` -------------------------------- ### Create a basic model summary Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/vignettes/get_started.html Generate a standard statistical model summary using the modelsummary function. This example uses a simple linear model. ```r fit <- lm(mpg ~ hp + wt, data = mtcars) modelsummary(fit) ``` -------------------------------- ### Generate a Model Summary with a Specific Theme and Font Size Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/vignettes/appearance.html This example demonstrates combining multiple appearance options, such as applying a 'markdown' theme and setting a 'normalsize' font. ```r modelsummary(model, theme = 'markdown', options = list('font_size' = 'normalsize')) ``` -------------------------------- ### Example of coef_omit with negative lookahead to keep coefficients Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/man/modelsummary.html Shows how to use a negative lookahead in a regular expression with `coef_omit` to keep coefficients that do not start with 'Vol'. ```R "^(?!Vol)" ``` -------------------------------- ### Applying Predefined Themes Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/vignettes/appearance.html Demonstrates the use of predefined themes to quickly change the overall appearance of the summary tables. This simplifies styling for consistent reports. ```r # Use the 'toluene' theme modelsummary(fit, theme = "toluene") # Use the 'sky' theme modelsummary(fit, theme = "sky") ``` -------------------------------- ### Interactive Mode Notice for modelsummary Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/LICENSE.html This is an example of a short notice displayed when the modelsummary program starts in interactive mode, indicating copyright, warranty, and redistribution conditions. ```text modelsummary Copyright (C) 2024 Vincent Arel-Bundock This program comes with ABSOLUTELY NO WARRANTY; for details type 'show w'. This is free software, and you are welcome to redistribute it under certain conditions; type 'show c' for details. ``` -------------------------------- ### Using Different Themes for Tables Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/vignettes/appearance.html Provides examples of applying various built-in themes to change the visual style of the summary tables. This offers quick ways to alter the table's appearance. ```r modelsummary(fit, theme = "basic") modelsummary(fit, theme = "scientific") modelsummary(fit, theme = "halway") ``` -------------------------------- ### Using Themes for Table Styling Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/vignettes/appearance.html Apply pre-defined themes to tables for quick styling using the `theme` argument. This allows for consistent and professional-looking tables. ```r modelsummary(model, theme = "striped") # Apply a striped theme ``` ```r modelsummary(model, theme = "ிறார்") # Apply a LaTeX-style theme ``` -------------------------------- ### Basic modelsummary Table in Quarto Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/vignettes/modelsummary.html Demonstrates a minimal Quarto document that generates a modelsummary table from an lm model. This example shows basic integration and cross-referencing capabilities. ```yaml --- format: pdf title: Example --- @tbl-mtcars shows that cars with high horse power get low miles per gallon. ::: {#tbl-mtcars .cell tbl-cap='Horse Powers vs. Miles per Gallon'} ```{.r .cell-code} library(modelsummary) mod <- lm(mpg ~ hp, mtcars) modelsummary(mod) ``` ::: ``` -------------------------------- ### Keep Coefficients Starting with 'Lit' Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/vignettes/modelsummary.html Uses a negative lookahead in `coef_omit` to keep coefficients that start with 'Lit'. Set `gof_map` to NA to omit goodness-of-fit statistics. ```r modelsummary(models, coef_omit = "^(?!Lit)", gof_map = NA) ``` -------------------------------- ### Basic sprintf Usage Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/man/fmt_sprintf.html Demonstrates the basic usage of sprintf for string formatting. This is useful for creating formatted output strings. ```javascript const r = setTimeout(() => { fn.apply(this, args); timer = throttle = false; }, ms); }; }; ``` -------------------------------- ### Selecting Specific Columns Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/vignettes/appearance.html Illustrates how to choose which columns to display in the summary table. This allows users to tailor the output to their specific analytical needs. ```r modelsummary(fit, columns = c("term", "estimate", "p.value"), # Only show term, estimate, and p-value fmt = 3) ``` -------------------------------- ### Tinytable Cell Styling Example Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/man/datasummary_correlation_format.html JavaScript code for styling specific cells in a Tinytable generated by modelsummary. This example demonstrates how to apply custom CSS classes to cells based on their position. ```javascript var cellsToStyle = [ { positions: [ { i: '3', j: 2 }, { i: '3', j: 3 }, { i: '3', j: 4 } ], css_id: 'tinytable_css_tppaxe9x9orotslra7g1'}, { positions: [ { i: '1', j: 2 }, { i: '2', j: 2 }, { i: '1', j: 3 }, { i: '2', j: 3 }, { i: '1', j: 4 }, { i: '2', j: 4 } ], css_id: 'tinytable_css_tu7gor6a98enva64jib5'}, { positions: [ { i: '0', j: 2 }, { i: '0', j: 3 }, { i: '0', j: 4 } ], css_id: 'tinytable_css_l9757xkokpspz36a146x'}, { positions: [ { i: '3', j: 1 } ], css_id: 'tinytable_css_c9v5ondhns8adeld2olr'}, { positions: [ { i: '1', j: 1 }, { i: '2', j: 1 } ], css_id: 'tinytable_css_i3j2tt5bm2ivtgdp25oi'}, { positions: [ { i: '0', j: 1 } ], css_id: 'tinytable_css_q654vfevyhixwnkrb8o9'}, ]; cellsToStyle.forEach(function (group) { group.positions.forEach(function (cell) { tableFns_hw37sz5ck53q20b3pnja.styleCell(cell.i, cell.j, group.css_id); }); }); ``` -------------------------------- ### Tinytable Styling Example Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/man/datasummary_skim.html This JavaScript code demonstrates how to create and style tables using the TinyTable library, often used in conjunction with data summary functions. ```javascript var cellsToStyle = [ // tinytable style arrays after { positions: [ { i: '5', j: 3 }, { i: '5', j: 4 } ], css_id: 'tinytable_css_a6zg274k5az00en2jgv6', }, { positions: [ { i: '1', j: 3 }, { i: '2', j: 3 }, { i: '3', j: 3 }, { i: '4', j: 3 }, { i: '1', j: 4 }, { i: '2', j: 4 }, { i: '3', j: 4 }, { i: '4', j: 4 } ], css_id: 'tinytable_css_videyqr8vbeexrmgdlul', }, { positions: [ { i: '0', j: 3 }, { i: '0', j: 4 } ], css_id: 'tinytable_css_175mn6g3v2akyu3hdek5', }, { positions: [ { i: '5', j: 1 }, { i: '5', j: 2 } ], css_id: 'tinytable_css_j7c70zqhmuzdsfs99lep', }, { positions: [ { i: '1', j: 1 }, { i: '2', j: 1 }, { i: '3', j: 1 }, { i: '4', j: 1 }, { i: '1', j: 2 }, { i: '2', j: 2 }, { i: '3', j: 2 }, { i: '4', j: 2 } ], css_id: 'tinytable_css_ewz515q55w8a89u0kobc', }, { positions: [ { i: '0', j: 1 }, { i: '0', j: 2 } ], css_id: 'tinytable_css_7lwhg9mesjccdybeeks8', }, ]; // Loop over the arrays to style the cells cellsToStyle.forEach(function (group) { group.positions.forEach(function (cell) { tableFns_1sc9fyazl0ad1ms158cr.styleCell(cell.i, cell.j, group.css_id); }); }); ``` -------------------------------- ### Control Table Appearance Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/vignettes/appearance.html Provides examples of controlling the appearance of the generated tables, such as adding borders or adjusting spacing. ```r library(modelsummary) # Generate a model summary with table appearance options modelsummary(mtcars, table_border = "all", row_sep = "none") ``` -------------------------------- ### Summarizing Models Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/vignettes/datasummary.html Demonstrates how to use datasummary to summarize statistical models. ```r fit1 <- lm(Sepal.Length ~ Sepal.Width, data = iris) fit2 <- lm(Petal.Length ~ Petal.Width, data = iris) modelsummary(list(fit1, fit2)) ``` -------------------------------- ### Create a Cross-Tabulation Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/vignettes/datasummary.html Use datasummary_crosstab to explore the association between two categorical variables. This example uses the penguins dataset. ```R library(modelsummary) url <- 'https://vincentarelbundock.github.io/Rdatasets/csv/palmerpenguins/penguins.csv' penguins <- read.csv(url, na.strings = "") datasummary_crosstab(species ~ sex, data = penguins) ``` -------------------------------- ### update_modelsummary Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/man/update_modelsummary.html Updates the modelsummary package and its dependencies to the latest available versions from R-Universe or CRAN. A session restart is required after installation. ```APIDOC ## update_modelsummary ### Description Update `modelsummary` and its dependencies to the latest R-Universe or CRAN versions. The R session needs to be restarted after install. ### Usage ```r update_modelsummary(source = "development") ``` ### Arguments * **source** (character) - Specifies the source for updates. Defaults to "development". ### Details This function is used to ensure you have the latest version of the `modelsummary` package and any associated dependencies. It is recommended to restart your R session after the update is complete for the changes to take effect. ``` -------------------------------- ### Passing Arguments to Sandwich Functions Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/vignettes/modelsummary.html Shows how to pass arguments to the underlying `sandwich` package functions directly from `modelsummary`. This example specifies bootstrap replicates and a clustering variable. ```R modelsummary(mod, vcov = "bootstrap", R = 1000, cluster = "country") ``` -------------------------------- ### Generating Tables in Different Formats Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/vignettes/datasummary.html Illustrates how to output the summary tables in various formats, such as HTML, LaTeX, and Markdown. ```r modelsummary(iris, output = "iris_summary.html") modelsummary(iris, output = "iris_summary.tex") modelsummary(iris, output = "iris_summary.md") ``` -------------------------------- ### Custom Correlation Function Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/man/datasummary_correlation.html Define and use a custom correlation function with datasummary_correlation. This example uses the Kendall correlation method. ```r # custom function cor_fun <- function(x) cor(x, method = "kendall") datasummary_correlation(dat, method = cor_fun) ``` -------------------------------- ### Categorical Data Summary Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/man/datasummary_skim.html Use datasummary_skim with type = "categorical" to get a summary of categorical variables in your dataset. ```R datasummary_skim(dat, type = "categorical") ``` -------------------------------- ### Apply a Theme Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/vignettes/appearance.html Use the `theme_modelsummary()` function to apply a predefined theme to your reports. This function accepts theme names like 'basic', 'journal', 'bootstrap', 'flatly', 'cerulean', 'spacelab', 'default', 'minimal', 'modern', 'striped', 'sky', 'emerald', 'red', 'darkly', 'lumen', 'sandstone', 'yeti', 'boring', 'ruins', 'marron', 'nature', 'clean', 'delight', 'solid', 'dracula', 'gruvbox', 'dracula_light', 'gruvbox_light'. ```r library(modelsummary) theme_modelsummary(theme = "journal") ``` -------------------------------- ### TinyTable Factory Function Source: https://github.com/vincentarelbundock/modelsummary/blob/main/inst/tinytest/_tinysnapshot/mathmode-null.html Creates table-specific functions using the TinyTable external factory. This is a setup step before styling cells. ```javascript const tableFns_m4thvn8u3cwpmj8hiuwk = TinyTable.createTableFunctions("tinytable_m4thvn8u3cwpmj8hiuwk"); ``` -------------------------------- ### Keep Coefficients by Substring (Negative Lookahead) Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/man/modelsummary.html Keep coefficients that start with a substring using a negative lookahead. All goodness-of-fit statistics are omitted. ```R modelsummary(models, coef_omit = "^(?!Vol)", gof_omit = ".*") ``` -------------------------------- ### Example of coef_omit with multiple substrings Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/man/modelsummary.html Illustrates omitting coefficients that match either 'ei' or 'rc' using a regular expression with `coef_omit`. ```R "ei|rc" ``` -------------------------------- ### Set Table Backend for Specific Formats Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/man/datasummary_balance.html Specify the table-making package to use for different output formats like HTML, Word, PNG, and LaTeX. ```R 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’) ``` -------------------------------- ### Example of gof_map with list of lists for formatting Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/man/modelsummary.html Provides detailed control over goodness-of-fit statistics formatting using a list of lists. Each inner list specifies 'raw', 'clean', and 'fmt' (which can be a string, number, or function). ```R list(list(raw = "r.squared", clean = "R-Squared", fmt = "%.3f")) ``` -------------------------------- ### Example of coef_omit with specific term omission Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/man/modelsummary.html Demonstrates omitting a specific coefficient named 'Volume' using a regular expression with `coef_omit`. ```R "^Volume$" ``` -------------------------------- ### Customizing Table Appearance with `columns` Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/vignettes/appearance.html Shows how to select and order the columns to be displayed in the summary table using the `columns` argument. This allows for precise control over the table's structure. ```r modelsummary(fit, columns = c("term", "estimate", "p.value")) ``` -------------------------------- ### Example of coef_omit with regular expression Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/man/modelsummary.html Shows how to use a regular expression with `coef_omit` to omit coefficients matching a specific substring, such as 'ei'. ```R "ei" ``` -------------------------------- ### Add custom statistics to model summary Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/vignettes/get_started.html Include additional custom statistics in your model summary. This example adds the R-squared value. ```r modelsummary(fit, statistic = "conf.int", add_rows = data.frame( "R-squared" = glance(fit)$r.squared, check_rows = "r.squared" ) ) ``` -------------------------------- ### Generate Data Summary Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/vignettes/get_started.html Use the `datasummary_skim` function to get a quick overview of the loaded dataset. This provides summary statistics for each variable. ```R datasummary_skim(dat) ``` -------------------------------- ### Load Libraries and Data Source: https://github.com/vincentarelbundock/modelsummary/blob/main/docs/vignettes/get_started.html Load necessary R packages and download a dataset from the Rdatasets archive. Prepare the data by creating a binary variable and selecting relevant columns. ```R library(modelsummary) library(tinytable) url <- 'https://vincentarelbundock.github.io/Rdatasets/csv/HistData/Guerry.csv' dat <- read.csv(url) dat$Small <- dat$Pop1831 > median(dat$Pop1831) dat <- dat[, c("Donations", "Literacy", "Commerce", "Crime_pers", "Crime_prop", "Clergy", "Small") ] ```