Graphing Predicted Legislative Violence with Zelig & ggplot2
[This article was first published on Christopher Gandrud, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
In my previous post I briefly mentioned an early draft of a working paper (HERE) I’ve written that looks into the possible causes of violence between legislators (like the violence shown in this picture from the Turkish Parliament). Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
From The Guardian |
In this post I’m going to briefly discuss how I used Zelig‘s rare events logistic regression (relogit) and ggplot2 in R to simulate and plot the legislative violence probabilities that are in the paper. In this example I am plotting simulated probabilities at fitted values on three variables:
- Age of democracy (Polity IV > 5)
- A dichotomous electoral proportionality variable where 1 is high proportionality, 0 otherwise (see here for more details)
- Governing parties’ majority (as a % of total legislative seats. Data is from DPI.)
Background
I used King and Zeng’s rare events logistic regression which they include in their R package Zelig to study incidences of legislative violence because (a) I was interested in a dichotomous outcome–whether or not a legislature had an incident of violence in a given year and (b) fortunately legislative violence is fairly rare. There are only 88 incidences in my data set spanning 1981 to Spring 2011 and even fewer (72) when I constricted the sample to 1981-2009, because there is limited data on many of my dependent variables after 2009.
Why GGPLOT2?
If you are familiar with the Zelig package, you’ll know that it already includes a capability to both simulate quantities of interest (for me it’s probabilities of violence given various values of the covariates) and plot the results from these simulations with uncertainty estimates.
To do this, first run the basic Zelig model then use setx() to set the range of covariate fitted values you are interested predicting probabilities for (all others are set to their means by default). Then use sim() to simulate the quantities of interest. Finally, just use plot() on the Zelig object that sim() creates. (See the full code at the end of the post.)
However these plots are . . . not incredibly visually appealing. Here is an example with various ages of democracy:
Plus, if you are not using base R plots in the rest of your paper, these types of plots will clash.
I used ggplot2 graphs in the rest of the paper so I wanted a way to plot simulated probabilities with ggplot2. Basically I wanted this:
Using GGPLOT2 and Zelig Simulation Output.
To leave a comment for the author, please follow the link and comment on their blog: Christopher Gandrud.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.