secret_weapon {dotwhisker}R Documentation

Generate a 'Secret Weapon' Plot of Regression Results from Multiple Models


secret_weapon is a function for plotting regression results of multiple models as a 'secret weapon' plot


secret_weapon(x, var = NULL, ci = 0.95, margins = FALSE, by_2sd = FALSE, ...)



Either a model object to be tidied with tidy, or a list of such model objects, or a tidy data frame of regression results (see 'Details').


The predictor whose results are to be shown in the 'secret weapon' plot


A number indicating the level of confidence intervals; the default is .95.


A logical value indicating whether presenting the average marginal effects of the estimates. See the Details for more information.


When x is a list of model objects, should the coefficients for predictors that are not binary be rescaled by twice the standard deviation of these variables in the dataset analyzed, per Gelman (2008)? Defaults to TRUE. Note that when x is a tidy data frame, one can use by_2sd to rescale similarly.


Arguments to pass to dwplot.


Andrew Gelman has coined the term "the secret weapon" for dot-and-whisker plots that compare the estimated coefficients for a single predictor across many models or datasets. secret_weapon takes a tidy data frame of regression results or a list of model objects and generates a dot-and-whisker plot of the results of a single variable across the multiple models.

Tidy data frames to be plotted should include the variables term (names of predictors), estimate (corresponding estimates of coefficients or other quantities of interest), std.error (corresponding standard errors), and model (identifying the corresponding model). In place of std.error one may substitute lb (the lower bounds of the confidence intervals of each estimate) and ub (the corresponding upper bounds).

Alternately, secret_weapon accepts as input a list of model objects that can be tidied by tidy (or tidy_parameters, parameters (with proper formatting)), or a list of such model objects.


The function returns a ggplot object.



# Estimate models across many samples, put results in a tidy data frame
by_clarity <- diamonds %>% group_by(clarity) %>%
 do(tidy(lm(price ~ carat + cut + color, data = .))) %>%
 ungroup %>% rename(model = clarity)

# Generate a 'secret weapon' plot of the results of diamond size
secret_weapon(by_clarity, "carat")

[Package dotwhisker version 0.7.0 Index]