Description Usage Arguments Details Value Examples

View source: R/secret_weapon.R

`secret_weapon`

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

1 |

`x` |
Either a model object to be tidied with |

`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 |

`...` |
Arguments to pass to |

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.

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

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.