modelplot | R Documentation |
Dot-Whisker plot of coefficient estimates with confidence intervals. For
more information, see the Details and Examples sections below, and the
vignettes on the modelsummary
website:
https://modelsummary.com/
modelplot(
models,
conf_level = 0.95,
coef_map = NULL,
coef_omit = NULL,
coef_rename = NULL,
vcov = NULL,
exponentiate = FALSE,
add_rows = NULL,
facet = FALSE,
draw = TRUE,
background = NULL,
...
)
models |
a model, (named) list of models, or nested list of models.
|
conf_level |
numeric value between 0 and 1. confidence level to use for
confidence intervals. Setting this argument to |
coef_map |
character vector. Subset, rename, and reorder coefficients.
Coefficients omitted from this vector are omitted from the table. The order
of the vector determines the order of the table. |
coef_omit |
integer vector or regular expression to identify which coefficients to omit (or keep) from the table. Positive integers determine which coefficients to omit. Negative integers determine which coefficients to keep. A regular expression can be used to omit coefficients, and perl-compatible "negative lookaheads" can be used to specify which coefficients to keep in the table. Examples:
|
coef_rename |
logical, named or unnamed character vector, or function
|
vcov |
robust standard errors and other manual statistics. The
|
exponentiate |
TRUE, FALSE, or logical vector of length equal to the
number of models. If TRUE, the |
add_rows |
a data.frame (or tibble) with the same number of columns as your main table. By default, rows are appended to the bottom of the table. You can define a "position" attribute of integers to set the row positions. See Examples section below. |
facet |
TRUE or FALSE. When the 'models' argument includes several model objects, TRUE draws terms in separate facets, and FALSE draws terms side-by-side (dodged). |
draw |
TRUE returns a 'ggplot2' object, FALSE returns the data.frame used to draw the plot. |
background |
A list of 'ggplot2' geoms to add to the background of the plot. This is especially useful to display annotations "behind" the 'geom_pointrange' that 'modelplot' draws. |
... |
all other arguments are passed through to three functions. See the documentation of these functions for lists of available arguments.
|
library(modelsummary) # single model mod <- lm(hp ~ vs + drat, mtcars) modelplot(mod) # omit terms with string matches or regexes modelplot(mod, coef_omit = 'Interc') # rename, reorder and subset with 'coef_map' cm <- c('vs' = 'V-shape engine', 'drat' = 'Rear axle ratio') modelplot(mod, coef_map = cm) # several models models <- list() models[['Small model']] <- lm(hp ~ vs, mtcars) models[['Medium model']] <- lm(hp ~ vs + factor(cyl), mtcars) models[['Large model']] <- lm(hp ~ vs + drat + factor(cyl), mtcars) modelplot(models) # add_rows: add an empty reference category mod <- lm(hp ~ factor(cyl), mtcars) add_rows = data.frame( term = "factory(cyl)4", model = "(1)", estimate = NA) attr(add_rows, "position") = 3 modelplot(mod, add_rows = add_rows) # customize your plots with 'ggplot2' functions library(ggplot2) modelplot(models) + scale_color_brewer(type = 'qual') + theme_classic() # pass arguments to 'geom_pointrange' through the ... ellipsis modelplot(mod, color = 'red', size = 1, fatten = .5) # add geoms to the background, behind geom_pointrange b <- list(geom_vline(xintercept = 0, color = 'orange'), annotate("rect", alpha = .1, xmin = -.5, xmax = .5, ymin = -Inf, ymax = Inf), geom_point(aes(y = term, x = estimate), alpha = .3, size = 10, color = 'red', shape = 'square')) modelplot(mod, background = b) # logistic regression example df <- as.data.frame(Titanic) mod_titanic <- glm( Survived ~ Class + Sex, family = binomial, weight = Freq, data = df ) # displaying odds ratio using a log scale modelplot(mod_titanic, exponentiate = TRUE) + scale_x_log10() + xlab("Odds Ratios and 95% confidence intervals")
Arel-Bundock V (2022). “modelsummary: Data and Model Summaries in R.” Journal of Statistical Software, 103(1), 1-23. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.18637/jss.v103.i01")}.'
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.