7.4 Visualizing Results

Now that we have our point estimates of our quantities of interest and our confidence intervals, we can kick it up a notch by visualizing these results.

Let’s plot our predicted probability when Allies = 1 with percentile Quasi-Bayesian CI’s and Bias-Corrected Bootstrap CI’s

plot(x = 1:2, y= c(pe1, pe1),
     ylim = c(0, .004),
     xlim = c(0.5, 2.5),
     pch = 20, cex = 1.6,
     main = "Average Predicted Probability of Dispute when Allies",
     cex.main = .7, cex.lab = .7, cex.axis = .7,
     ylab = "Predicted Probability",
     xlab = "", 
     xaxt = "n") # removes x-axis
# add lines from c(x1, x2) on the x-axis and from c(y1, y2) on the y-axis
# note, we don't want any horizontal movement, so we keep x1 and x2 the same c(1,1)
lines(c(1,1), c(quantile(qestimates, c(0.025, 0.975))), lwd = 1.5)
lines(c(2,2), c(quantile(bc, c(0.025, .975))), lwd = 1.5)
# add text a
text(c(1, 2), c(0.001, 0.001), c("Quasi-Bayesian", "BC Bootstrap"), cex = .7 )

Here is the same but in ggplot form.

## ggplot works best if you create a dataframe of the data you want to plot
myg <- data.frame(rbind(c(pe1, quantile(qestimates, c(0.025, 0.975))),
                       c(pe1, quantile(bc, c(0.025, .975)))))
colnames(myg) <- c("pp", "qb", "bc") 
myg
           pp          qb          bc
1 0.002759902 0.002314344 0.003419644
2 0.002759902 0.002088520 0.003244449
## now provide this dataframe to ggplot
ggplot(myg, aes(x = 1:nrow(myg), y = pp))+ 
  geom_point(stat = "identity", size = 3) +
  geom_errorbar(data=myg, aes(x =1:nrow(myg),  
                         ymin = qb, ymax = bc), 
                width = 0, size = 1.1) +
  xlim(.5, 2.5) +
  ylim(0, .005) +
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank(),
        plot.title = element_text(hjust = 0.5)) +
  ylab("Predicted Probability") +
  ggtitle("Average Predicted Probability of Dispute when Allies") +
  annotate("text", x = c(1,2), y = .004, label = c("Quasi-Bayesian", "BC Bootstrap"))