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

Description Usage Arguments Details Value Examples

View source: R/secret_weapon.R

Description

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

Usage

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

Arguments

x

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').

var

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

ci

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

margins

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

by_2sd

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.

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 (or tidy_parameters, parameters (with proper formatting)), or a list of such model objects.

Value

The function returns a ggplot object.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
library(dplyr)
library(broom)

# 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")

dotwhisker documentation built on July 17, 2021, 9:08 a.m.