Extract model estimates in a tidy format.Source:
This is a mostly internal function which could be useful to users who want
a unified approach to extract results from a wide variety of models. For
get_estimates attaches useful attributes to the output. You
can access this information by calling the
get_estimates( model, conf_level = 0.95, vcov = NULL, shape = NULL, coef_rename = FALSE, ... )
a single model object
numeric value between 0 and 1. confidence level to use for confidence intervals. Setting this argument to
NULLdoes not extract confidence intervals, which can be faster for some models.
robust standard errors and other manual statistics. The
vcovargument accepts six types of input (see the 'Details' and 'Examples' sections below):
NULL returns the default uncertainty estimates of the model object
string, vector, or (named) list of strings. "iid", "classical", and "constant" are aliases for
NULL, which returns the model's default uncertainty estimates. The strings "HC", "HC0", "HC1" (alias: "stata"), "HC2", "HC3" (alias: "robust"), "HC4", "HC4m", "HC5", "HAC", "NeweyWest", "Andrews", "panel-corrected", "outer-product", and "weave" use variance-covariance matrices computed using functions from the
sandwichpackage, or equivalent method. The behavior of those functions can (and sometimes must) be altered by passing arguments to
modelsummarythrough the ellipsis (
...), but it is safer to define your own custom functions as described in the next bullet.
function or (named) list of functions which return variance-covariance matrices with row and column names equal to the names of your coefficient estimates (e.g.,
function(x) vcovPC(x, cluster="country")).
formula or (named) list of formulas with the cluster variable(s) on the right-hand side (e.g., ~clusterid).
named list of
length(models)variance-covariance matrices with row and column names equal to the names of your coefficient estimates.
a named list of length(models) vectors with names equal to the names of your coefficient estimates. See 'Examples' section below. Warning: since this list of vectors can include arbitrary strings or numbers,
modelsummarycannot automatically calculate p values. The
starsargument may thus use incorrect significance thresholds when
vcovis a list of vectors.
NULL, formula, or string which determines the shape of a table.
NULL: Default shape with terms in rows and models in columns.
Formula: The left side determines what appears on rows, and the right side determines what appears on columns. The formula can include one or more group identifier(s) to display related terms together, which can be useful for models with multivariate outcomes or grouped coefficients (See examples section below). The group identifier(s) must be column names produced by:
get_estimates(model). The group identifier(s) can be combined with the term identifier in a single column by using the colon to represent an interaction. If an incomplete formula is supplied (e.g.,
modelsummarytries to complete it automatically. Goodness-of-fit statistics are only appended to the bottom of the table when
modelis on the right hand side of the formula (i.e., columns). Potential
term + statistic ~ model: default
term ~ model + statistic: statistics in separate columns
model + statistic ~ term: models in rows and terms in columns
term + response + statistic ~ model: term and group id in separate columns
term : response + statistic ~ model: term and group id in a single column
term ~ response
String: "rbind" or "rcollapse" to bind rows of two or more regression tables to create "panels" or "stacks" of regression models.
modelsargument must be a (potentially named) nested list of models.
Unnamed nested list with 2 panels:
list(list(model1, model2), list(model3, model4))
Named nested list with 2 panels:
list("Panel A" = list(model1, model2), "Panel B" = list(model3, model4))
Named panels and named models:
list("Panel A" = list("(I)" = model1, "(II)" = model2), "Panel B" = list("(I)" = model3, "(II)" = model4))
"rbind": Bind the rows of independent regression tables
"rcollapse": Bind the rows of regression tables and create a panel at the bottom where we "collapse" goodness-of-fit statistics which are identical across models.
logical, named or unnamed character vector, or function
Logical: TRUE renames variables based on the "label" attribute of each column. See the Example section below.
Unnamed character vector of length equal to the number of coefficients in the final table, after
Named character vector: Values refer to the variable names that will appear in the table. Names refer to the original term names stored in the model object. Ex: c("hp:mpg"="hp X mpg")
Function: Accepts a character vector of the model's term names and returns a named vector like the one described above. The
modelsummarypackage supplies a
coef_rename()function which can do common cleaning tasks:
modelsummary(model, coef_rename = coef_rename)
all other arguments are passed through to three functions. See the documentation of these functions for lists of available arguments.
parameters::model_parameters extracts parameter estimates. Available arguments depend on model type, but include:
performance::model_performance extracts goodness-of-fit statistics. Available arguments depend on model type, but include:
kableExtra::kbl or gt::gt draw tables, depending on the value of the