POL 300: Lab 7

Author

Dr. Annie Karreth

This page contains R code for Lab 7.

Instructions

To complete this lab:

  • create a new R script on your computer
  • save it under the name POL 300 Lab 7.R
  • copy and paste the code from this page (in the gray boxes) into the script
  • comment the code as instructed during the lab

Code

# install.packages("RCPA3")
# install.packages("marginaleffects")
library(RCPA3)
library(marginaleffects)
setwd(dirname(rstudioapi::getSourceEditorContext()$path))
getwd()
regC(formula = peace.index ~ fh.democ.score, 
     data = world)
regC(formula = vep20.turnout ~ battleground2020, 
     data = states)
plot(x = world$fh.democ.score, 
     y = world$peace.index)

abline(a = 2.324, 
       b = 0.011)
regC(formula = vep20.turnout ~ battleground2020,
                      data = states)
turnout.model1 <- regC(formula = vep20.turnout ~ battleground2020,
                      data = states)
plot_predictions(model = turnout.model1, 
                 condition = "battleground2020") + 
  labs(x = "Battleground state in 2020 election?", 
       y = "Expected percentage voter turnout",
       title = "Effect of Battleground Status on State Voter Turnout",
       caption = "Note: Vertical segments are 95% confidence intervals.")
regC(formula = vep20.turnout ~ battleground2020 + hs.or.more,
     data = states)
turnout.model2 <- regC(formula = vep20.turnout ~ battleground2020 + hs.or.more,
     data = states)
plot_predictions(turnout.model2, condition = "battleground2020") + 
  labs(x = "Battleground state in 2020 election?", 
       y = "Expected percentage voter turnout",
       title = "Effect of Battleground Status on State Voter Turnout",
       caption = "Note: Vertical segments are 95% confidence intervals.")
plot_predictions(turnout.model2, condition = "hs.or.more") + 
  labs(x = "Battleground state in 2020 election?", 
       y = "Expected percentage voter turnout",
       title = "Effect of education on State Voter Turnout",
       caption = "Note: Gray area shows 95% confidence intervals.")
regC(formula = peace.index ~ fh.democ.score + trade.percent.gdp,
     data = world)