Chapter 20 Issue: Road toll

if(!require("broom")){install.packages("broom");  library(broom)}
if(!require("haven")){install.packages("haven");  library(haven)}
if(!require("here")){install.packages("here");  library(here)}
if(!require("knitr")){install.packages("knitr");  library(knitr)}
if(!require("kableExtra")){install.packages("kableExtra");  library(kableExtra)}
if(!require("naniar")){install.packages("naniar");  library(naniar)}
if(!require("tidyverse")){install.packages("tidyverse");  library(tidyverse)}

set.seed(2016)

d <- read_sav("C:\\Users/Sveinung/OneDrive/NORCE 2018-/goodloser/Conjoint/Bookdown-goodloser/Data/Goodloser-exp3.sav")

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

20.1 Main effects

20.1.1 Prepare data

main_01 <- d %>% 
  mutate(rsp_id = as.numeric(responseid),
         rsp_beg = case_when(r13pad1 == 1 ~ "In favour of ban on begging",
                             r13pad1 == 2 ~ "Against ban on begging"),
         rsp_beg_imp = case_when(r13pad2 %in% 1:2 ~ "Important",
                                  r13pad2 %in% 3:5 ~ "Not important"),
         rsp_toll = case_when(r13pad3 == 1 ~ "In favour of road toll increase of diesel cars",
                              r13pad3 == 2 ~ "Against road toll increase of diesel cars"),
         rsp_toll_imp = case_when(r13pad4 %in% 1:2 ~ "Important",
                                  r13pad4 %in% 3:5 ~ "Not important"),
         treat_issue = case_when(r13pad5_sak == 1 ~ "Ban on begging",
                               r13pad5_sak == 2 ~ "Road toll increase of diesel cars"),
         treat_outcome = case_when(r13pad5_utfall == 1 ~ "The Yes side won the vote",
                                 r13pad5_utfall == 2 ~ "The No side won the vote"),
          treat_outfav = case_when(r13pad5_sak == 1 & r13pad1 == 1 & r13pad5_utfall == 1 ~ "Favorable outcome",
                                  r13pad5_sak == 1 & r13pad1 == 2 & r13pad5_utfall == 2 ~ "Favorable outcome",
                                  r13pad5_sak == 1 & r13pad1 == 1 & r13pad5_utfall == 2 ~ "Unfavorable outcome",
                                  r13pad5_sak == 1 & r13pad1 == 2 & r13pad5_utfall == 1 ~ "Unfavorable outcome",
                                  r13pad5_sak == 2 & r13pad3 == 1 & r13pad5_utfall == 1 ~ "Favorable outcome",
                                  r13pad5_sak == 2 & r13pad3 == 2 & r13pad5_utfall == 2 ~ "Favorable outcome",
                                  r13pad5_sak == 2 & r13pad3 == 1 & r13pad5_utfall == 2 ~ "Unfavorable outcome",
                                  r13pad5_sak == 2 & r13pad3 == 2 & r13pad5_utfall == 1 ~ "Unfavorable outcome"),
         treat_winningmargin = case_when(r13pad5_vinnermargin == 1 ~ "Not shown",
                                       r13pad5_vinnermargin == 2 ~ "Slight majority",
                                       r13pad5_vinnermargin == 3 ~ "Large majority"),
         treat_winnergloat = case_when(r13pad5_vinner == 1 ~ "Not shown",
                                     r13pad5_vinner == 2 ~ "Winning politician gloats"),
        treat_prime = case_when(r13pad5_avsender == 1 ~ "Not shown",
                               r13pad5_avsender == 2  | r13pad5_avsender == 5 ~ "No prime",
                               r13pad5_avsender == 3  | r13pad5_avsender == 6 ~ "Specific prime",
                               r13pad5_avsender == 4 | r13pad5_avsender == 7 ~ "General prime"),
         treat_messenger = case_when(r13pad5_avsender %in% 3:4 ~ "Political leader",
                                   r13pad5_avsender %in% 6:7 ~ "Local newspaper"),
         post_fair = case_when(r13pad6a == 1 | r13pad6b == 1 ~ 5,
                          r13pad6a == 2 | r13pad6b == 2 ~ 4,
                          r13pad6a == 3 | r13pad6b == 3 ~ 3,
                          r13pad6a == 4 | r13pad6b == 4 ~ 2,
                          r13pad6a == 5 | r13pad6b == 5 ~ 1),
          post_reasonable = case_when(r13pad7a == 1 | r13pad7b == 1 ~ 5,
                          r13pad7a == 2 | r13pad7b == 2 ~ 4,
                          r13pad7a == 3 | r13pad7b == 3 ~ 3,
                          r13pad7a == 4 | r13pad7b == 4 ~ 2,
                          r13pad7a == 5 | r13pad7b == 5 ~ 1),
          post_accept = case_when(r13pad8a == 1 | r13pad8b == 1 ~ 5,
                          r13pad8a == 2 | r13pad8b == 2 ~ 4,
                          r13pad8a == 3 | r13pad8b == 3 ~ 3,
                          r13pad8a == 4 | r13pad8b == 4 ~ 2,
                          r13pad8a == 5 | r13pad8b == 5 ~ 1)

  ) %>% 

  replace_with_na_all(condition = ~.x == 98 )%>%  #Recode 98 (not asked) as missing
  filter(!is.na(r13pad6_ran)) %>%  #Remove NA's
## We want the value labels in particular order for the tables and figures.
        mutate(treat_winningmargin = lvls_reorder(treat_winningmargin, c(2, 3, 1)), 
               treat_prime = lvls_reorder(treat_prime, c(3, 2, 4, 1))
        )
main_01 <- main_01 %>%   
      filter(treat_issue == "Road toll increase of diesel cars")

20.1.2 Reasonable decision

source("Functions/amce.R")

res_main <-  main_01 %>%
  amce(post_reasonable, treat_outfav, treat_winningmargin, treat_winnergloat, treat_prime, treat_messenger) 
  
res_main <- res_main %>% 
  mutate(
  treatment =  case_when(treatment == "treat_outfav" ~ "Outcome\nfavor-\nability",
            treatment == "treat_winningmargin" ~ "Winning\nmargin",
            treatment == "treat_winnergloat" ~ "Winner\ngloats",
            treatment == "treat_prime" ~ "Democratic\nprime",
            treatment == "treat_messenger" ~ "Primer")
)

#Figure
fig_amce <-
  res_main %>%
  ggplot(aes(x = estimate, y = value)) +
  facet_grid(
    treatment ~ .,
    scales = "free_y",
    space = "free_y") +
  geom_errorbarh(
    aes(xmin = estimate - (2 * std_error),
        xmax = estimate + (2 * std_error)),
    height = 0) +
  geom_point() +
  geom_vline(aes(xintercept = 0), linetype = "dotted") +
  scale_x_continuous(
    limits = c(-1.2, 1.2),
    breaks = round(seq(-1.2, 1.2, .1), 2),
    expand = c(0, 0)) +
   labs(
    x = "Marginal effect, reasonable decision",
    y = "Decision process attributes") +
  theme_bw() +
  theme(plot.margin = unit(c(2, 2, 2, 2), "mm")) +
  theme(panel.spacing = unit(0.5, "lines"))
fig_amce

ggsave(
  here("output", "figs", "pngs", "fig_toll_reasonable.png"),
  plot = fig_amce,
  width = 5.5, height = 2.75
)
## Error in grDevices::png(..., res = dpi, units = "in"): unable to start png() device
ggsave(
  here("output", "figs", "pdfs", "fig_toll_reasonable.pdf"),
  plot = fig_amce,
  width = 5.5, height = 2.75
)
## Error in grDevices::pdf(file = filename, ..., version = version): cannot open file 'C:/Users/Sveinung/OneDrive/NORCE 2018-/goodloser/Conjoint/Bookdown-goodloser/output/figs/pdfs/fig_toll_reasonable.pdf'
#Table
res_main <- res_main %>% 
  select(value, estimate, std_error, statistic, p_value)

kable(res_main, booktabs = TRUE, caption = "Average Marginal Component Effects", col.names = linebreak(c("Treatment value", "Estimate", "Std. Error", "t-statistic", "p value"))) %>% 
  kable_styling(bootstrap_options = c("striped", "hover", "responsive")) %>% 
 group_rows(index = c("Outcome favorability" = 2, "Winning margin" = 3, "Winner gloating" = 2, "Good loser prime" = 4, "Primer" = 2))
(#tab:309_toll_post_reasonable)Average Marginal Component Effects
Treatment value Estimate Std. Error t-statistic p value
Outcome favorability
Favorable outcome 0.0000000 0.0000000 NA NA
Unfavorable outcome -1.0424899 0.0603840 -17.2643387 0.0000000
Winning margin
Not shown 0.0000000 0.0000000 NA NA
Slight majority -0.0191919 0.0810457 -0.2368031 0.8128456
Large majority -0.0213037 0.0815982 -0.2610804 0.7940705
Winner gloating
Not shown 0.0000000 0.0000000 NA NA
Winning politician gloats 0.0170354 0.0665671 0.2559127 0.7980574
Good loser prime
Not shown 0.0000000 0.0000000 NA NA
No prime 0.0251244 0.1090041 0.2304903 0.8177459
Specific prime 0.2030055 0.1106496 1.8346690 0.0667758
General prime 0.2780702 0.1091307 2.5480465 0.0109434
Primer
Local newspaper 0.0000000 0.0000000 NA NA
Political leader 0.0049231 0.0863941 0.0569839 0.9545729

20.1.3 Willingnes to accept

source("Functions/amce.R")

res_main <-  main_01 %>%
  amce(post_accept, treat_outfav, treat_winningmargin, treat_winnergloat, treat_prime, treat_messenger) 
  

res_main <- res_main %>% 
  mutate(
  treatment =  case_when(treatment == "treat_outfav" ~ "Outcome\nfavor-\nability",
            treatment == "treat_winningmargin" ~ "Winning\nmargin",
            treatment == "treat_winnergloat" ~ "Winner\ngloats",
            treatment == "treat_prime" ~ "Democratic\nprime",
            treatment == "treat_messenger" ~ "Primer")
)

#Figure
fig_amce <-
  res_main %>%
  ggplot(aes(x = estimate, y = value)) +
  facet_grid(
    treatment ~ .,
    scales = "free_y",
    space = "free_y") +
  geom_errorbarh(
    aes(xmin = estimate - (2 * std_error),
        xmax = estimate + (2 * std_error)),
    height = 0) +
  geom_point() +
  geom_vline(aes(xintercept = 0), linetype = "dotted") +
  scale_x_continuous(
    limits = c(-1, 1),
    breaks = round(seq(-1, 1, .1), 2),
    expand = c(0, 0)) +
   labs(
    x = "Marginal effect, willingnes to accept decision",
    y = "Decision process attributes") +
  theme_bw() +
  theme(plot.margin = unit(c(2, 2, 2, 2), "mm"))
fig_amce

ggsave(
  here("output", "figs", "pngs", "fig_toll_accept.png"),
  plot = fig_amce,
  width = 5.5, height = 2.75
)
## Error in grDevices::png(..., res = dpi, units = "in"): unable to start png() device
ggsave(
  here("output", "figs", "pdfs", "fig_toll_accept.pdf"),
  plot = fig_amce,
  width = 5.5, height = 2.75
)
## Error in grDevices::pdf(file = filename, ..., version = version): cannot open file 'C:/Users/Sveinung/OneDrive/NORCE 2018-/goodloser/Conjoint/Bookdown-goodloser/output/figs/pdfs/fig_toll_accept.pdf'
#table
res_main <- res_main %>% 
  select(value, estimate, std_error, statistic, p_value)


kable(res_main, booktabs = TRUE, caption = "Average Marginal Component Effects", col.names = linebreak(c("Treatment value", "Estimate", "Std. Error", "t-statistic", "p value"))) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "responsive")) %>% 
 group_rows(index = c("Outcome favorability" = 2, "Winning margin" = 3, "Winner gloating" = 2, "Good loser prime" = 4, "Primer" = 2))
(#tab:309_toll_post_accept)Average Marginal Component Effects
Treatment value Estimate Std. Error t-statistic p value
Outcome favorability
Favorable outcome 0.0000000 0.0000000 NA NA
Unfavorable outcome -0.7704678 0.0590577 -13.0460101 0.0000000
Winning margin
Not shown 0.0000000 0.0000000 NA NA
Slight majority -0.0427296 0.0757104 -0.5643826 0.5725874
Large majority -0.0167328 0.0763971 -0.2190245 0.8266641
Winner gloating
Not shown 0.0000000 0.0000000 NA NA
Winning politician gloats 0.0197767 0.0622694 0.3175988 0.7508383
Good loser prime
Not shown 0.0000000 0.0000000 NA NA
No prime 0.0574264 0.1016701 0.5648311 0.5722825
Specific prime 0.3040591 0.1031171 2.9486787 0.0032463
General prime 0.2620604 0.1017887 2.5745543 0.0101427
Primer
Local newspaper 0.0000000 0.0000000 NA NA
Political leader 0.0224788 0.0792548 0.2836265 0.7767731

20.1.4 Fairness perceptions

source("Functions/amce.R")

res_main <-  main_01 %>%
  amce(post_fair, treat_outfav, treat_winningmargin, treat_winnergloat, treat_prime, treat_messenger)
  
res_main <- res_main %>% 
  mutate(
  treatment =  case_when(treatment == "treat_outfav" ~ "Outcome\nfavor-\nability",
            treatment == "treat_winningmargin" ~ "Winning\nmargin",
            treatment == "treat_winnergloat" ~ "Winner\ngloats",
            treatment == "treat_prime" ~ "Democratic\nprime",
            treatment == "treat_messenger" ~ "Primer")
)

#Figure
fig_amce <-
  res_main %>%
  ggplot(aes(x = estimate, y = value)) +
  facet_grid(
    treatment ~ .,
    scales = "free_y",
    space = "free_y") +
  geom_errorbarh(
    aes(xmin = estimate - (2 * std_error),
        xmax = estimate + (2 * std_error)),
    height = 0) +
  geom_point() +
  geom_vline(aes(xintercept = 0), linetype = "dotted") +
  scale_x_continuous(
    limits = c(-1, 1),
    breaks = round(seq(-1, 1, .1), 2),
    expand = c(0, 0)) +
   labs(
    x = "Marginal effect, perceived fairness of decision",
    y = "Decision process attributes") +
  theme_bw() +
  theme(plot.margin = unit(c(2, 2, 2, 2), "mm"))
fig_amce

ggsave(
  here("output", "figs", "pngs", "fig_toll_fair.png"),
  plot = fig_amce,
  width = 5.5, height = 2.75
)
## Error in grDevices::png(..., res = dpi, units = "in"): unable to start png() device
ggsave(
  here("output", "figs", "pdfs", "fig_toll_fair.pdf"),
  plot = fig_amce,
  width = 5.5, height = 2.75
)
## Error in grDevices::pdf(file = filename, ..., version = version): cannot open file 'C:/Users/Sveinung/OneDrive/NORCE 2018-/goodloser/Conjoint/Bookdown-goodloser/output/figs/pdfs/fig_toll_fair.pdf'
#table
res_main <- res_main %>% 
  select(value, estimate, std_error, statistic, p_value)


kable(res_main, booktabs = TRUE, caption = "Average Marginal Component Effects", col.names = linebreak(c("Treatment value", "Estimate", "Std. Error", "t-statistic", "p value"))) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "responsive")) %>% 
 group_rows(index = c("Outcome favorability" = 2, "Winning margin" = 3, "Winner gloating" = 2, "Good loser prime" = 4, "Primer" = 2))
(#tab:309_toll_post_fair)Average Marginal Component Effects
Treatment value Estimate Std. Error t-statistic p value
Outcome favorability
Favorable outcome 0.0000000 0.0000000 NA NA
Unfavorable outcome -0.4596607 0.0576524 -7.9729616 0.0000000
Winning margin
Not shown 0.0000000 0.0000000 NA NA
Slight majority -0.0014252 0.0714199 -0.0199554 0.9840819
Large majority 0.0188783 0.0719864 0.2622482 0.7931701
Winner gloating
Not shown 0.0000000 0.0000000 NA NA
Winning politician gloats 0.0582165 0.0586798 0.9921043 0.3213242
Good loser prime
Not shown 0.0000000 0.0000000 NA NA
No prime 0.2510179 0.0959742 2.6154742 0.0090097
Specific prime 0.3589214 0.0973349 3.6874894 0.0002355
General prime 0.3670244 0.0960483 3.8212485 0.0001388
Primer
Local newspaper 0.0000000 0.0000000 NA NA
Political leader -0.0384543 0.0743049 -0.5175200 0.6049422