Learn R Programming

dotwhisker (version 0.2.0.5)

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

Description

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

Usage

secret_weapon(x, var = NULL, alpha = 0.05)

Arguments

x
Either a tidy data.frame including results from multiple models (see 'Details') or a list of model objects that can be tidied with tidy
var
The predictor whose results are to be shown in the 'secret weapon' plot
alpha
A number setting the criterion of the confidence intervals. The default value is .05, corresponding to 95-percent confidence intervals.

Value

The function returns a ggplot object.

Details

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.

Examples

Run this code
library(broom)
library(dplyr)

# Estimate models across many samples, put results in a tidy data.frame
by_clarity <- diamonds %>% group_by(clarity) %>%
 do(broom::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")


Run the code above in your browser using DataLab