Chapter 5 CAMCE’s

Average Marginal Component Effects of turnout level, majority size, and outcome favorability.

if(!require("broom")){install.packages("broom");  library(broom)}
if(!require(descr2)) {devtools::install_github("mikajoh/descr2"); library(descr2)}
if(!require("forcats")){install.packages("forcats");  library(forcats)}
if(!require("ggplot2")){install.packages("ggplot2");  library(ggplot2)}
if(!require("haven")){install.packages("haven");  library(haven)}
if(!require("here")){install.packages("here");  library(here)}
if(!require("kableExtra")){install.packages("kableExtra");  library(kableExtra)}
if(!require("knitr")){install.packages("knitr");  library(knitr)}
if(!require("lmtest")){install.packages("lmtest");  library(lmtest)}
if(!require("sandwich")){install.packages("sandwich");  library(sandwich)}
if(!require("tidyverse")){install.packages("tidyverse");  library(tidyverse)}

knitr::opts_chunk$set(echo = FALSE, knitr.kable.NA = "", cache = FALSE, warning = FALSE, message = FALSE, error = TRUE, echo = FALSE)

#load data
d <- read_sav("Data/EIPS2017-data/eips-wiggle-pooled.sav")

#Function for saving output
ggsave2 <- function(filename, ...) {
  for (format in c(".pdf", ".png")) ggsave(filename = paste0("output/", filename, format), ...)
}


## Functions for calculating AMCE's.
source("wiggle-utils.R")

## Theme for ggplot2.
theme_m <- function(...) {
  theme(text = element_text(size = 9,
                            colour = "black"),
        axis.text = element_text(size = 7,
                                 colour = "black"),
        axis.title = element_text(size = 8,
                                  colour = "black"),
        axis.line = element_line(),
        axis.ticks = element_line(colour = "black"),
        axis.ticks.length = unit(1, "mm"),
        plot.margin = unit(c(1, 5, 1, 1), "mm"),
        panel.spacing.x = unit(7.5, "mm"),
        panel.spacing.y = unit(2.5, "mm"),
        panel.background = element_blank(),
        panel.grid.major = element_blank(),
        strip.background = element_blank(),
        strip.text = element_text(size = 7,
                                  face = "bold"),
        strip.text.y = element_text(angle = 0, face = "bold.italic"),
        legend.background = element_blank(),
        legend.key = element_blank(),
        legend.position = "bottom",
        ...)
}

add_labels <- function(amce) {
  
  labels <- data.frame(
    treatment = c(
      "ref_turnout",
      "ref_majoritysize",
      "ref_winningside",
      "ref_outcome"
    ),
    treatment_label = c(
      "Turnout",
      "Majority size",
      "Winning side",
      "Outcome favorability"
    ),
    stringsAsFactors = FALSE
  )
  
  amce <- amce[rev(order(amce$value)), ]
  amce$value <- paste0("plain('", as.character(amce$value), "')")
  amce$value <- factor(amce$value, levels = unique(amce$value))
  add_data <- labels[labels$treatment %in% amce$treatment, ]
  names(add_data)[2] <- "value"
  add_data$value <- gsub("\n", " ", as.character(add_data$value))
  add_data$value <- paste0("bold('", add_data$value, "')")
  for (var in c("value_order", "estimate", "std_error", "statistic", "p_value")) {
    add_data[[var]] <- NA
  }
  add_data$value_order <- -Inf
  if (any(!(names(amce) %in% names(add_data)))) {
    for (.c in names(amce)[!(names(amce) %in% names(add_data))]) {
      add_data[[.c]] <- amce[[.c]][1]
    }
  }
  if (any(!(names(add_data) %in% names(amce)))) {
    for (.c in names(add_data)[!(names(add_data) %in% names(amce))]) {
      add_data <- add_data[, -c(which(names(add_data) == .c))]
    }
  }
  amce <- rbind(amce, add_data)
  amce <- amce[order(amce$treatment, amce$value_order), ]
  return(amce)
}

eips <- eips_raw 

eips <- eips %>%
  mutate(
    ref_turnout = lvls_reorder(factor(ref_turnout),
                               c(5, 4:1)),
    ref_majoritysize = lvls_reorder(factor(ref_majoritysize),
                                    c(4, 3:1)),
    ref_winner = lvls_reorder(factor(ref_winner), 
                              c(2, 1, 3)),
    ref_outcome =  lvls_reorder(factor(ref_outcome),
                                c(2, 1, 3))
    
  ) 

## Write prepared data to file.
save(eips, file = "output/eips-wiggle-prepared-data.RData")

## Load the prepared data.
load("output/eips-wiggle-prepared-data.RData")
Table 5.1: Average Marginal Component Effects, Conditional on Outcome Favorability
ref_outcome Treatment Value Estimate Std.error t.statistic
Not shown Turnout Not shown 0.0000000 0.0000000 NA
Not shown Turnout 85% 0.0579733 0.0187149 3.0977034
Not shown Turnout 53% -0.0442623 0.0187273 -2.3635152
Not shown Turnout 47% -0.1292752 0.0187232 -6.9045542
Not shown Turnout 35% -0.2041553 0.0188892 -10.8080587
Favorable outcome Turnout Not shown 0.0000000 0.0000000 NA
Favorable outcome Turnout 85% 0.0202834 0.0177683 1.1415454
Favorable outcome Turnout 53% -0.0636476 0.0179427 -3.5472633
Favorable outcome Turnout 47% -0.1041038 0.0179613 -5.7960031
Favorable outcome Turnout 35% -0.1613754 0.0174635 -9.2407037
Unfavorable outcome Turnout Not shown 0.0000000 0.0000000 NA
Unfavorable outcome Turnout 85% 0.0263387 0.0219661 1.1990643
Unfavorable outcome Turnout 53% -0.0953758 0.0218031 -4.3744226
Unfavorable outcome Turnout 47% -0.1684346 0.0219997 -7.6562171
Unfavorable outcome Turnout 35% -0.2103855 0.0217196 -9.6864474
Not shown Majority size Not shown 0.0000000 0.0000000 NA
Not shown Majority size 70% 0.0342749 0.0171501 1.9985229
Not shown Majority size 55% -0.0335545 0.0173061 -1.9388854
Not shown Majority size 51% -0.0389690 0.0164569 -2.3679381
Favorable outcome Majority size Not shown 0.0000000 0.0000000 NA
Favorable outcome Majority size 70% 0.0041500 0.0162894 0.2547701
Favorable outcome Majority size 55% -0.0545771 0.0163406 -3.3399689
Favorable outcome Majority size 51% -0.0352046 0.0152625 -2.3066125
Unfavorable outcome Majority size Not shown 0.0000000 0.0000000 NA
Unfavorable outcome Majority size 70% -0.0114943 0.0202411 -0.5678700
Unfavorable outcome Majority size 55% -0.0336291 0.0197602 -1.7018618
Unfavorable outcome Majority size 51% -0.0573047 0.0188676 -3.0372055
## 
## Call:
## lm(formula = ref_post ~ ref_turnout + ref_majoritysize + ref_outcome + 
##     ref_turnout:ref_outcome + ref_outcome:ref_majoritysize, data = eips)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.8963 -0.5204  0.2212  0.3224  0.5535 
## 
## Coefficients:
##                                                     Estimate Std. Error
## (Intercept)                                         0.752919   0.015929
## ref_turnout85%                                      0.056294   0.018369
## ref_turnout53%                                     -0.046509   0.018385
## ref_turnout47%                                     -0.130506   0.018376
## ref_turnout35%                                     -0.202145   0.018544
## ref_majoritysize70%                                 0.031700   0.016541
## ref_majoritysize55%                                -0.030375   0.016681
## ref_majoritysize51%                                -0.031870   0.015872
## ref_outcomeFavorable outcome                        0.118264   0.023443
## ref_outcomeUnfavorable outcome                     -0.043441   0.023955
## ref_turnout85%:ref_outcomeFavorable outcome        -0.035302   0.026982
## ref_turnout53%:ref_outcomeFavorable outcome        -0.017071   0.027134
## ref_turnout47%:ref_outcomeFavorable outcome         0.026833   0.027141
## ref_turnout35%:ref_outcomeFavorable outcome         0.041986   0.026857
## ref_turnout85%:ref_outcomeUnfavorable outcome      -0.028851   0.027449
## ref_turnout53%:ref_outcomeUnfavorable outcome      -0.047924   0.027344
## ref_turnout47%:ref_outcomeUnfavorable outcome      -0.036456   0.027477
## ref_turnout35%:ref_outcomeUnfavorable outcome      -0.006962   0.027399
## ref_majoritysize70%:ref_outcomeFavorable outcome   -0.027566   0.024374
## ref_majoritysize55%:ref_outcomeFavorable outcome   -0.022749   0.024508
## ref_majoritysize51%:ref_outcomeFavorable outcome   -0.001571   0.023095
## ref_majoritysize70%:ref_outcomeUnfavorable outcome -0.044503   0.024802
## ref_majoritysize55%:ref_outcomeUnfavorable outcome -0.003977   0.024570
## ref_majoritysize51%:ref_outcomeUnfavorable outcome -0.022033   0.023424
##                                                    t value Pr(>|t|)    
## (Intercept)                                         47.267  < 2e-16 ***
## ref_turnout85%                                       3.065  0.00218 ** 
## ref_turnout53%                                      -2.530  0.01142 *  
## ref_turnout47%                                      -7.102 1.28e-12 ***
## ref_turnout35%                                     -10.901  < 2e-16 ***
## ref_majoritysize70%                                  1.916  0.05533 .  
## ref_majoritysize55%                                 -1.821  0.06863 .  
## ref_majoritysize51%                                 -2.008  0.04467 *  
## ref_outcomeFavorable outcome                         5.045 4.59e-07 ***
## ref_outcomeUnfavorable outcome                      -1.813  0.06979 .  
## ref_turnout85%:ref_outcomeFavorable outcome         -1.308  0.19077    
## ref_turnout53%:ref_outcomeFavorable outcome         -0.629  0.52928    
## ref_turnout47%:ref_outcomeFavorable outcome          0.989  0.32285    
## ref_turnout35%:ref_outcomeFavorable outcome          1.563  0.11799    
## ref_turnout85%:ref_outcomeUnfavorable outcome       -1.051  0.29323    
## ref_turnout53%:ref_outcomeUnfavorable outcome       -1.753  0.07968 .  
## ref_turnout47%:ref_outcomeUnfavorable outcome       -1.327  0.18460    
## ref_turnout35%:ref_outcomeUnfavorable outcome       -0.254  0.79942    
## ref_majoritysize70%:ref_outcomeFavorable outcome    -1.131  0.25809    
## ref_majoritysize55%:ref_outcomeFavorable outcome    -0.928  0.35329    
## ref_majoritysize51%:ref_outcomeFavorable outcome    -0.068  0.94576    
## ref_majoritysize70%:ref_outcomeUnfavorable outcome  -1.794  0.07278 .  
## ref_majoritysize55%:ref_outcomeUnfavorable outcome  -0.162  0.87143    
## ref_majoritysize51%:ref_outcomeUnfavorable outcome  -0.941  0.34691    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4481 on 15863 degrees of freedom
##   (1518 observations deleted due to missingness)
## Multiple R-squared:  0.06455,    Adjusted R-squared:  0.06319 
## F-statistic: 47.59 on 23 and 15863 DF,  p-value: < 2.2e-16
Table 5.1: Average Marginal Component Effects, Conditional on Outcome Favorability
term Estimate Std.error t.statistic p.value
(Intercept) 0.7529194 0.0159292 47.2665087 0.0000000
ref_turnout85% 0.0562941 0.0183694 3.0645652 0.0021835
ref_turnout53% -0.0465091 0.0183850 -2.5297381 0.0114244
ref_turnout47% -0.1305057 0.0183762 -7.1019052 0.0000000
ref_turnout35% -0.2021451 0.0185438 -10.9009523 0.0000000
ref_majoritysize70% 0.0317001 0.0165413 1.9164190 0.0553297
ref_majoritysize55% -0.0303754 0.0166806 -1.8209985 0.0686259
ref_majoritysize51% -0.0318703 0.0158721 -2.0079493 0.0446656
ref_outcomeFavorable outcome 0.1182636 0.0234434 5.0446439 0.0000005
ref_outcomeUnfavorable outcome -0.0434408 0.0239554 -1.8134054 0.0697882
ref_turnout85%:ref_outcomeFavorable outcome -0.0353022 0.0269822 -1.3083481 0.1907742
ref_turnout53%:ref_outcomeFavorable outcome -0.0170709 0.0271343 -0.6291264 0.5292754
ref_turnout47%:ref_outcomeFavorable outcome 0.0268330 0.0271413 0.9886412 0.3228538
ref_turnout35%:ref_outcomeFavorable outcome 0.0419862 0.0268566 1.5633474 0.1179909
ref_turnout85%:ref_outcomeUnfavorable outcome -0.0288512 0.0274486 -1.0510993 0.2932290
ref_turnout53%:ref_outcomeUnfavorable outcome -0.0479237 0.0273437 -1.7526378 0.0796835
ref_turnout47%:ref_outcomeUnfavorable outcome -0.0364563 0.0274769 -1.3267965 0.1845951
ref_turnout35%:ref_outcomeUnfavorable outcome -0.0069621 0.0273992 -0.2540999 0.7994217
ref_majoritysize70%:ref_outcomeFavorable outcome -0.0275656 0.0243737 -1.1309565 0.2580905
ref_majoritysize55%:ref_outcomeFavorable outcome -0.0227491 0.0245076 -0.9282445 0.3532949
ref_majoritysize51%:ref_outcomeFavorable outcome -0.0015713 0.0230947 -0.0680369 0.9457571
ref_majoritysize70%:ref_outcomeUnfavorable outcome -0.0445029 0.0248024 -1.7943004 0.0727843
ref_majoritysize55%:ref_outcomeUnfavorable outcome -0.0039766 0.0245699 -0.1618496 0.8714264
ref_majoritysize51%:ref_outcomeUnfavorable outcome -0.0220330 0.0234239 -0.9406202 0.3469139