A unified approach to extract results from a wide variety of models.
Usage
get_estimates(
model,
conf_level = 0.95,
vcov = NULL,
shape = NULL,
coef_rename = FALSE,
...
)Arguments
- model
a single model object
- conf_level
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.- vcov
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 thesandwichpackage, or equivalent method. "BS", "bootstrap", "residual", "mammen", "webb", "xy", "wild" use thesandwich::vcovBS(). The behavior of those functions can (and sometimes must) be altered by passing arguments tosandwichdirectly frommodelsummarythrough 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.,
stats::vcov,sandwich::vcovHC,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. Thestarsargument may thus use incorrect significance thresholds whenvcovis a list of vectors.
- shape
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.,~statistic),modelsummarytries to complete it automatically. Goodness-of-fit statistics are only appended to the bottom of the table whenmodelis on the right hand side of the formula (i.e., columns). Potentialshapevalues include:term + statistic ~ model: defaultterm ~ model + statistic: statistics in separate columnsmodel + statistic ~ term: models in rows and terms in columnsterm + response + statistic ~ model: term and group id in separate columnsterm : response + statistic ~ model: term and group id in a single columnterm ~ response
String: "cbind", "rbind", "rcollapse"
"cbind": side-by-side models with autmoatic spanning column headers to group models (
tinytableonly feature)."rbind" or "rcollapse": "panels" or "stacks" of regression models.
the
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.
- coef_rename
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. Note: renaming is done by the
parameterspackage at the extraction stage, before other arguments are applied likecoef_omit. Therefore, this only works for models with builtin support and not for custom models.Unnamed character vector of length equal to the number of coefficients in the final table, after
coef_omitis applied.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 acoef_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:
standardize,include_reference,centrality,dispersion,test,ci_method,prior,diagnostic,rope_range,power,cluster, etc.
performance::model_performance extracts goodness-of-fit statistics. Available arguments depend on model type, but include:
metrics,estimator, etc.
tinytable::tt, kableExtra::kbl or gt::gt draw tables, depending on the value of the
outputargument. For example, by defaultmodelsummarycreates tables with tinytable::tt, which accepts awidthandthemearguments.
Value
A dataframe with model estimates.
The backend attribute of the returned object contains the backend that was used to extract parameters from the model.
Moreover, for some models, get_estimates attaches useful attributes to the output.
You can access this information by calling the attributes function: attributes(get_estimates(model)).