library(foreign)
library(tidyverse)
library(dotwhisker)
library(emmeans)
library(broom)
library(stevemisc)
library(ggpubr)
library(lemon)
library(expss)
library(ggtext)
library(qqplotr)
library(gt)
library(insight)
library(pwr)
library(effsize)
# Set working directory
setwd("C:/Users/Alan/Dropbox/Nottingham Research Fellow/Negativity Experiment/EJPR/PDF Figures")
# Import data
yougov3 <- read.spss("C:/Users/Alan/Documents/YouGov3.sav", to.data.frame = TRUE)
# Create function to help with descriptives
table_count <- function(x, table_object1, table_object2) {
if(missing(table_object2)) {
table_out <- addmargins(table(table_object1),c(x),sum)
} else {
table_out <- addmargins(table(table_object1, table_object2),c(x),sum)
}
return(table_out)
}
# Create variable to indicate which party is engaging in the negative messaging
yougov3$attacker <-
case_when(
yougov3$qgroup_exp == "1" ~ "labour",
yougov3$qgroup_exp == "3" ~ "labour",
yougov3$qgroup_exp == "4" ~ "labour",
yougov3$qgroup_exp == "5" ~ "labour",
yougov3$qgroup_exp == "2" ~ "tory",
yougov3$qgroup_exp == "6" ~ "tory",
yougov3$qgroup_exp == "7" ~ "tory",
yougov3$qgroup_exp == "8" ~ "tory")
yougov3$target <-
case_when(
yougov3$qgroup_exp == "1" ~ "tory",
yougov3$qgroup_exp == "3" ~ "tory",
yougov3$qgroup_exp == "4" ~ "tory",
yougov3$qgroup_exp == "5" ~ "tory",
yougov3$qgroup_exp == "2" ~ "labour",
yougov3$qgroup_exp == "6" ~ "labour",
yougov3$qgroup_exp == "7" ~ "labour",
yougov3$qgroup_exp == "8" ~ "labour")
# Create variables for labour, tory, and pooled treatment groups
yougov3$labour_groups <-
case_when(
yougov3$qgroup_exp == "1" ~ "Control",
yougov3$qgroup_exp == "3" ~ "Treat1",
yougov3$qgroup_exp == "4" ~ "Treat2",
yougov3$qgroup_exp == "5" ~ "Treat3")
yougov3$labour_groups <- as.factor(yougov3$labour_groups)
yougov3$tory_groups <-
case_when(
yougov3$qgroup_exp == "2" ~ "Control",
yougov3$qgroup_exp == "6" ~ "Treat1",
yougov3$qgroup_exp == "7" ~ "Treat2",
yougov3$qgroup_exp == "8" ~ "Treat3")
yougov3$tory_groups <- as.factor(yougov3$tory_groups)
yougov3$pooled_groups <-
case_when(
yougov3$qgroup_exp == "1" ~ "Control",
yougov3$qgroup_exp == "3" ~ "Treat1",
yougov3$qgroup_exp == "4" ~ "Treat2",
yougov3$qgroup_exp == "5" ~ "Treat3",
yougov3$qgroup_exp == "2" ~ "Control",
yougov3$qgroup_exp == "6" ~ "Treat1",
yougov3$qgroup_exp == "7" ~ "Treat2",
yougov3$qgroup_exp == "8" ~ "Treat3")
yougov3$pooled_groups <- as.factor(yougov3$pooled_groups)
# Create partisanship variable
table_count(1,yougov3$partyid_2017)
yougov3$partisan <-
case_when(
yougov3$partyid_2017 == "Labour" & yougov3$attacker == "labour" ~ "Attacker Copartisan",
yougov3$partyid_2017 == "Conservative" & yougov3$attacker == "tory" ~ "Attacker Copartisan",
yougov3$partyid_2017 == "Labour" & yougov3$target == "labour" ~ "Target Copartisan",
yougov3$partyid_2017 == "Conservative" & yougov3$target == "tory" ~ "Target Copartisan",
yougov3$partyid_2017 == "No – None" ~ "Non-partisan",
yougov3$partyid_2017 == "Don't know" ~ "Non-partisan",
is.na(yougov3$partyid_2017) ~ NA_character_,
TRUE ~ "Out-party")
yougov3$partisan <- as.factor(yougov3$partisan)
table_count(1,yougov3$partisan)
table(yougov3$partyid_2017, yougov3$partisan)
# Attacking candidates
# Recode negativity variables
yougov3$NU1_Q4_Lab <- dplyr::recode(yougov3$NU1_Q4_Lab, "10 - Very positive" = "10",
"5 - Neither negative nor positive" = "5",
"0 - Very negative" = "0")
yougov3$NU1_Q4_Lab <- as.numeric(yougov3$NU1_Q4_Lab)
yougov3$NU1_Q4_Lab <- revcode(yougov3$NU1_Q4_Lab)
yougov3$NU2_Q4_Con <- dplyr::recode(yougov3$NU2_Q4_Con, "10 - Very positive" = "10",
"5 - Neither negative nor positive" = "5",
"0 - Very negative" = "0")
yougov3$NU2_Q4_Con <- as.numeric(yougov3$NU2_Q4_Con)
yougov3$NU2_Q4_Con <- revcode(yougov3$NU2_Q4_Con)
# Create aggregate negativity variable
yougov3$Q4_neg1 <- with(yougov3, ifelse(attacker == "labour", NU1_Q4_Lab, NU2_Q4_Con))
# Perceived negativity of attacking candidate
# Pooled candidates
reg1 <- lm(Q4_neg1 ~ pooled_groups, data=yougov3, weights = yougov3$weight)
summary(reg1)
# Pairwise comparison analysis for pooled candidates
pairwise1_def <- pairs(emmeans(reg1, ~ pooled_groups), adjust = "none")
pairwise1_rev <- pairs(emmeans(reg1, ~ pooled_groups), reverse = TRUE, adjust = "none")
pairwise1_def <- tidy(pairwise1_def, conf.int = TRUE)
pairwise1_rev <- tidy(pairwise1_rev, conf.int = TRUE)
pairwise1_def <- pairwise1_def[c(4,5),]
pairwise1_rev <- pairwise1_rev[c(1,2,4,6),]
pairwise1 <- rbind(pairwise1_rev, pairwise1_def)
pairwise1$order <- c(1,2,3,5,4,6)
# Partisanship analysis for pooled candidates
reg2 <- lm(Q4_neg1 ~ pooled_groups*partisan, data=yougov3, weights = yougov3$weight)
summary(reg2)
pairwise2_def <- pairs(emmeans(reg2, ~ pooled_groups*partisan), adjust = "none")
pairwise2_rev <- pairs(emmeans(reg2, ~ pooled_groups*partisan), reverse = TRUE, adjust = "none")
pairwise2_def <- tidy(pairwise2_def, conf.int = TRUE)
pairwise2_rev <- tidy(pairwise2_rev, conf.int = TRUE)
pairwise2_def_ac <- pairwise2_def[c(16,17),]
pairwise2_rev_ac <- pairwise2_rev[c(1,2,4,6),]
pairwise2_ac <- rbind(pairwise2_rev_ac, pairwise2_def_ac)
pairwise2_ac$model <- 1
pairwise2_ac$N <- 418
pairwise2_ac$order <- c(1,2,3,5,4,6)
pairwise2_ac$contrast <- str_replace_all(pairwise2_ac$contrast, "Attacker Copartisan", "")
pairwise2_ac$contrast <- str_replace_all(pairwise2_ac$contrast, " ", "")
pairwise2_def_tc <- pairwise2_def[c(118,119),]
pairwise2_rev_tc <- pairwise2_rev[c(91,104,118,120),]
pairwise2_tc <- rbind(pairwise2_rev_tc, pairwise2_def_tc)
pairwise2_tc$model <- 2
pairwise2_tc$N <- 383
pairwise2_tc$order <- c(1,2,3,5,4,6)
pairwise2_tc$contrast <- str_replace_all(pairwise2_tc$contrast, "Target Copartisan", "")
pairwise2_tc$contrast <- str_replace_all(pairwise2_tc$contrast, " ", "")
pairwise2_def_np <- pairwise2_def[c(66,67),]
pairwise2_rev_np <- pairwise2_rev[c(15,20,26,28),]
pairwise2_np <- rbind(pairwise2_rev_np, pairwise2_def_np)
pairwise2_np$model <- 3
pairwise2_np$N <- 351
pairwise2_np$order <- c(1,2,3,5,4,6)
pairwise2_np$contrast <- str_replace_all(pairwise2_np$contrast, "Non-partisan", "")
pairwise2_np$contrast <- gsub("[][(]", "", pairwise2_np$contrast)
pairwise2_np$contrast <- gsub("[][)]", "", pairwise2_np$contrast)
pairwise2_np$contrast <- str_replace_all(pairwise2_np$contrast, " ", "")
pairwise2_def_op <- pairwise2_def[c(100,101),]
pairwise2_rev_op <- pairwise2_rev[c(45,54,64,66),]
pairwise2_op <- rbind(pairwise2_rev_op, pairwise2_def_op)
pairwise2_op$model <- 4
pairwise2_op$N <- 262
pairwise2_op$order <- c(1,2,3,5,4,6)
pairwise2_op$contrast <- str_replace_all(pairwise2_op$contrast, "Out-party", "")
pairwise2_op$contrast <- gsub("[][(]", "", pairwise2_op$contrast)
pairwise2_op$contrast <- gsub("[][)]", "", pairwise2_op$contrast)
pairwise2_op$contrast <- str_replace_all(pairwise2_op$contrast, " ", "")
pairwise2 <- rbind(pairwise2_ac, pairwise2_tc, pairwise2_np, pairwise2_op)
pairwise2 <- subset(pairwise2, select = -c(1))
pairwise2 <- rename(pairwise2, term="contrast")
val_lab(pairwise2$model) = num_lab("
1 Attacker Copartisan
2 Target Copartisan
3 Non-Partisan
4 Out-Party
")
png("Figure3.png", width = 7, height = 6, units = "in", res = 300)
ggplot(pairwise2, aes(x = term, y = estimate) ) +
geom_point(aes(color = p.value < 0.05)) +
geom_pointrange(aes(ymin = conf.low, ymax = conf.high, color = p.value < 0.05), size = 0.15) +
coord_flip() +
scale_x_discrete(limits=rev) +
geom_hline(yintercept=0, linetype="dashed", color="grey50") +
theme_classic() +
facet_wrap(~model, scales = "fixed", nrow=2, ncol=2, strip.position = "top") +
theme(strip.placement = "outside") +
labs(x = NULL, y = "Degree of negativity (Attacker)") +
scale_x_discrete(limits=c("Treat1-Treat3","Treat3-Treat2","Treat1-Treat2",
"Treat3-Control", "Treat2-Control", "Treat1-Control"),
breaks=c("Treat1-Treat3","Treat3-Treat2","Treat1-Treat2",
"Treat3-Control", "Treat2-Control", "Treat1-Control"),
labels=c("**Personal Vs**
Both", "**Both Vs**
Policy", "**Personal Vs**
Policy",
"**Both Vs**
Control", "**Policy Vs**
Control", "**Personal Vs**
Control")) +
theme(axis.text.y=element_markdown(size=11.5, color="black"),
axis.title=element_text(size=12),
strip.text = element_text(size = 12, face = "bold")) +
scale_color_manual(values = c("TRUE" = "black", "FALSE" = "darkgrey"), guide="none"
)
dev.off()
# Export results as table with main stats
treatment_order <- c("Treat1-Control", "Treat2-Control", "Treat3-Control",
"Treat1-Treat2", "Treat3-Treat2", "Treat1-Treat3")
pairwise2$term <- factor(pairwise2$term, levels = treatment_order)
pairwise2 <- pairwise2[,c(1, 3:4, 6:11)]
pairwise2 <- pairwise2 %>%
arrange(model, term)
colnames(pairwise2) <- c("Treatment", "Estimate", "Std Error", "95% CI Lower", "95% CI Upper", "t stat", "p-value", "Model", "N")
pairwise2 <- pairwise2 %>%
mutate(Treatment = case_when(
Treatment == "Treat1-Control" ~ "Personal-Control",
Treatment == "Treat2-Control" ~ "Policy-Control",
Treatment == "Treat3-Control" ~ "Both-Control",
Treatment == "Treat1-Treat2" ~ "Personal-Policy",
Treatment == "Treat3-Treat2" ~ "Both-Policy",
TRUE ~ "Personal-Both"
))
html_table <- pairwise2 %>%
gt() %>%
fmt_number(
columns = "p-value",
decimals = 5
) %>%
fmt_number(
columns = c("Estimate", "Std Error", "95% CI Lower", "95% CI Upper", "t stat"),
decimals = 2
) %>%
tab_style(
style = cell_text(weight = "bold"),
locations = cells_body(
columns = everything(),
rows = `p-value` < 0.05
)
)
html_table |> gtsave("table_S6.docx", type = "docx")
# Favourability analysis
# Attacking candidate
# Recode favourability variables
yougov3$NU1_Q1_Lab <- dplyr::recode(yougov3$NU1_Q1_Lab, "10 - Very favourable" = "10",
"5 - Neither unfavourable nor favourable" = "5",
"0 - Very unfavourable" = "0")
yougov3$NU1_Q1_Lab <- as.numeric(yougov3$NU1_Q1_Lab)
yougov3$NU2_Q1_Con <- dplyr::recode(yougov3$NU2_Q1_Con, "10 - Very favourable" = "10",
"5 - Neither unfavourable nor favourable" = "5",
"0 - Very unfavourable" = "0")
yougov3$NU2_Q1_Con <- as.numeric(yougov3$NU2_Q1_Con)
# Create aggregate favourability variables
yougov3$Q1_fav_attacker <- with(yougov3, ifelse(attacker == "labour", NU1_Q1_Lab, NU2_Q1_Con))
# Pooled candidates
reg3 <- lm(Q1_fav_attacker ~ pooled_groups, data=yougov3, weights = yougov3$weight)
summary(reg3)
# Pairwise comparison analysis for pooled candidates
pairwise3_def <- pairs(emmeans(reg3, ~ pooled_groups), adjust = "none")
pairwise3_rev <- pairs(emmeans(reg3, ~ pooled_groups), reverse = TRUE, adjust = "none")
pairwise3_def <- tidy(pairwise3_def, conf.int = TRUE)
pairwise3_rev <- tidy(pairwise3_rev, conf.int = TRUE)
pairwise3_def <- pairwise3_def[c(4,5),]
pairwise3_rev <- pairwise3_rev[c(1,2,4,6),]
pairwise3 <- rbind(pairwise3_rev, pairwise3_def)
pairwise3$order <- c(1,2,3,5,4,6)
# Partisanship analysis for pooled candidates
reg4 <- lm(Q1_fav_attacker ~ pooled_groups*partisan, data=yougov3, weights = yougov3$weight)
summary(reg4)
pairwise4_def <- pairs(emmeans(reg4, ~ pooled_groups*partisan), adjust = "none")
pairwise4_rev <- pairs(emmeans(reg4, ~ pooled_groups*partisan), reverse = TRUE, adjust = "none")
pairwise4_def <- tidy(pairwise4_def, conf.int = TRUE)
pairwise4_rev <- tidy(pairwise4_rev, conf.int = TRUE)
pairwise4_def_ac <- pairwise4_def[c(16,17),]
pairwise4_rev_ac <- pairwise4_rev[c(1,2,4,6),]
pairwise4_ac <- rbind(pairwise4_rev_ac, pairwise4_def_ac)
pairwise4_ac$model <- 1
pairwise4_ac$N <- 418
pairwise4_ac$order <- c(1,2,3,5,4,6)
pairwise4_ac$contrast <- str_replace_all(pairwise4_ac$contrast, "Attacker Copartisan", "")
pairwise4_ac$contrast <- str_replace_all(pairwise4_ac$contrast, " ", "")
pairwise4_def_tc <- pairwise4_def[c(118,119),]
pairwise4_rev_tc <- pairwise4_rev[c(91,104,118,120),]
pairwise4_tc <- rbind(pairwise4_rev_tc, pairwise4_def_tc)
pairwise4_tc$model <- 2
pairwise4_tc$N <- 383
pairwise4_tc$order <- c(1,2,3,5,4,6)
pairwise4_tc$contrast <- str_replace_all(pairwise4_tc$contrast, "Target Copartisan", "")
pairwise4_tc$contrast <- str_replace_all(pairwise4_tc$contrast, " ", "")
pairwise4_def_np <- pairwise4_def[c(66,67),]
pairwise4_rev_np <- pairwise4_rev[c(15,20,26,28),]
pairwise4_np <- rbind(pairwise4_rev_np, pairwise4_def_np)
pairwise4_np$model <- 3
pairwise4_np$N <- 351
pairwise4_np$order <- c(1,2,3,5,4,6)
pairwise4_np$contrast <- str_replace_all(pairwise4_np$contrast, "Non-partisan", "")
pairwise4_np$contrast <- gsub("[][(]", "", pairwise4_np$contrast)
pairwise4_np$contrast <- gsub("[][)]", "", pairwise4_np$contrast)
pairwise4_np$contrast <- str_replace_all(pairwise4_np$contrast, " ", "")
pairwise4_def_op <- pairwise4_def[c(100,101),]
pairwise4_rev_op <- pairwise4_rev[c(45,54,64,66),]
pairwise4_op <- rbind(pairwise4_rev_op, pairwise4_def_op)
pairwise4_op$model <- 4
pairwise4_op$N <- 262
pairwise4_op$order <- c(1,2,3,5,4,6)
pairwise4_op$contrast <- str_replace_all(pairwise4_op$contrast, "Out-party", "")
pairwise4_op$contrast <- gsub("[][(]", "", pairwise4_op$contrast)
pairwise4_op$contrast <- gsub("[][)]", "", pairwise4_op$contrast)
pairwise4_op$contrast <- str_replace_all(pairwise4_op$contrast, " ", "")
pairwise4 <- rbind(pairwise4_ac, pairwise4_tc, pairwise4_np, pairwise4_op)
pairwise4 <- subset(pairwise4, select = -c(1))
pairwise4 <- rename(pairwise4, term="contrast")
val_lab(pairwise4$model) = num_lab("
1 Attacker Copartisan
2 Target Copartisan
3 Non-Partisan
4 Out-Party
")
png("Figure4.png", width = 7, height = 6, units = "in", res = 300)
ggplot(pairwise4, aes(x = term, y = estimate) ) +
geom_point(aes(color = p.value < 0.05)) +
geom_pointrange(aes(ymin = conf.low, ymax = conf.high, color = p.value < 0.05), size = 0.15) +
coord_flip() +
scale_x_discrete(limits=rev) +
geom_hline(yintercept=0, linetype="dashed", color="grey50") +
theme_classic() +
facet_wrap(~model, scales = "fixed", nrow=2, ncol=2, strip.position = "top") +
theme(strip.placement = "outside") +
labs(x = NULL, y = "Favourability (Attacker)") +
scale_x_discrete(limits=c("Treat1-Treat3","Treat3-Treat2","Treat1-Treat2",
"Treat3-Control", "Treat2-Control", "Treat1-Control"),
breaks=c("Treat1-Treat3","Treat3-Treat2","Treat1-Treat2",
"Treat3-Control", "Treat2-Control", "Treat1-Control"),
labels=c("**Personal Vs**
Both", "**Both Vs**
Policy", "**Personal Vs**
Policy",
"**Both Vs**
Control", "**Policy Vs**
Control", "**Personal Vs**
Control")) +
theme(axis.text.y=element_markdown(size=11.5, color="black"),
axis.title=element_text(size=12),
strip.text = element_text(size = 12, face = "bold")) +
scale_color_manual(values = c("TRUE" = "black", "FALSE" = "darkgrey"), guide="none"
)
dev.off()
# Export results as table with main stats
treatment_order <- c("Treat1-Control", "Treat2-Control", "Treat3-Control",
"Treat1-Treat2", "Treat3-Treat2", "Treat1-Treat3")
pairwise4$term <- factor(pairwise4$term, levels = treatment_order)
pairwise4 <- pairwise4[,c(1, 3:4, 6:11)]
pairwise4 <- pairwise4 %>%
arrange(model, term)
colnames(pairwise4) <- c("Treatment", "Estimate", "Std Error", "95% CI Lower", "95% CI Upper", "t stat", "p-value", "Model", "N")
pairwise4 <- pairwise4 %>%
mutate(Treatment = case_when(
Treatment == "Treat1-Control" ~ "Personal-Control",
Treatment == "Treat2-Control" ~ "Policy-Control",
Treatment == "Treat3-Control" ~ "Both-Control",
Treatment == "Treat1-Treat2" ~ "Personal-Policy",
Treatment == "Treat3-Treat2" ~ "Both-Policy",
TRUE ~ "Personal-Both"
))
html_table <- pairwise4 %>%
gt() %>%
fmt_number(
columns = "p-value",
decimals = 5
) %>%
fmt_number(
columns = c("Estimate", "Std Error", "95% CI Lower", "95% CI Upper", "t stat"),
decimals = 2
) %>%
tab_style(
style = cell_text(weight = "bold"),
locations = cells_body(
columns = everything(),
rows = `p-value` < 0.05
)
)
html_table |> gtsave("table_S7.docx", type = "docx")
# Favourability (Targeted candidate)
# Targeted candidate
yougov3$NU1_Q1_Con <- dplyr::recode(yougov3$NU1_Q1_Con, "10 - Very favourable" = "10",
"5 - Neither unfavourable nor favourable" = "5",
"0 - Very unfavourable" = "0")
yougov3$NU1_Q1_Con <- as.numeric(yougov3$NU1_Q1_Con)
yougov3$NU2_Q1_Lab <- dplyr::recode(yougov3$NU2_Q1_Lab, "10 - Very favourable" = "10",
"5 - Neither unfavourable nor favourable" = "5",
"0 - Very unfavourable" = "0")
yougov3$NU2_Q1_Lab <- as.numeric(yougov3$NU2_Q1_Lab)
# Create aggregate favourability variables
# Targeted candidates
yougov3$Q1_fav_target <- with(yougov3, ifelse(target == "tory", NU1_Q1_Con, NU2_Q1_Lab))
# Pooled candidates
reg5 <- lm(Q1_fav_target ~ pooled_groups, data=yougov3, weights = yougov3$weight)
summary(reg5)
pairwise5_def <- pairs(emmeans(reg5, ~ pooled_groups), adjust = "none")
pairwise5_rev <- pairs(emmeans(reg5, ~ pooled_groups), reverse = TRUE, adjust = "none")
pairwise5_def <- tidy(pairwise5_def, conf.int = TRUE)
pairwise5_rev <- tidy(pairwise5_rev, conf.int = TRUE)
pairwise5_def <- pairwise5_def[c(4,5),]
pairwise5_rev <- pairwise5_rev[c(1,2,4,6),]
pairwise5 <- rbind(pairwise5_rev, pairwise5_def)
pairwise5$order <- c(1,2,3,5,4,6)
# Partisanship analysis for pooled candidates
reg6 <- lm(Q1_fav_target ~ pooled_groups*partisan, data=yougov3, weights = yougov3$weight)
summary(reg6)
pairwise6_def <- pairs(emmeans(reg6, ~ pooled_groups*partisan), adjust = "none")
pairwise6_rev <- pairs(emmeans(reg6, ~ pooled_groups*partisan), reverse = TRUE, adjust = "none")
pairwise6_def <- tidy(pairwise6_def, conf.int = TRUE)
pairwise6_rev <- tidy(pairwise6_rev, conf.int = TRUE)
pairwise6_def_ac <- pairwise6_def[c(16,17),]
pairwise6_rev_ac <- pairwise6_rev[c(1,2,4,6),]
pairwise6_ac <- rbind(pairwise6_rev_ac, pairwise6_def_ac)
pairwise6_ac$model <- 1
pairwise6_ac$N <- 418
pairwise6_ac$order <- c(1,2,3,5,4,6)
pairwise6_ac$contrast <- str_replace_all(pairwise6_ac$contrast, "Attacker Copartisan", "")
pairwise6_ac$contrast <- str_replace_all(pairwise6_ac$contrast, " ", "")
pairwise6_def_tc <- pairwise6_def[c(118,119),]
pairwise6_rev_tc <- pairwise6_rev[c(91,104,118,120),]
pairwise6_tc <- rbind(pairwise6_rev_tc, pairwise6_def_tc)
pairwise6_tc$model <- 2
pairwise6_tc$N <- 383
pairwise6_tc$order <- c(1,2,3,5,4,6)
pairwise6_tc$contrast <- str_replace_all(pairwise6_tc$contrast, "Target Copartisan", "")
pairwise6_tc$contrast <- str_replace_all(pairwise6_tc$contrast, " ", "")
pairwise6_def_np <- pairwise6_def[c(66,67),]
pairwise6_rev_np <- pairwise6_rev[c(15,20,26,28),]
pairwise6_np <- rbind(pairwise6_rev_np, pairwise6_def_np)
pairwise6_np$model <- 3
pairwise6_np$N <- 351
pairwise6_np$order <- c(1,2,3,5,4,6)
pairwise6_np$contrast <- str_replace_all(pairwise6_np$contrast, "Non-partisan", "")
pairwise6_np$contrast <- gsub("[][(]", "", pairwise6_np$contrast)
pairwise6_np$contrast <- gsub("[][)]", "", pairwise6_np$contrast)
pairwise6_np$contrast <- str_replace_all(pairwise6_np$contrast, " ", "")
pairwise6_def_op <- pairwise6_def[c(100,101),]
pairwise6_rev_op <- pairwise6_rev[c(45,54,64,66),]
pairwise6_op <- rbind(pairwise6_rev_op, pairwise6_def_op)
pairwise6_op$model <- 4
pairwise6_op$N <- 262
pairwise6_op$order <- c(1,2,3,5,4,6)
pairwise6_op$contrast <- str_replace_all(pairwise6_op$contrast, "Out-party", "")
pairwise6_op$contrast <- gsub("[][(]", "", pairwise6_op$contrast)
pairwise6_op$contrast <- gsub("[][)]", "", pairwise6_op$contrast)
pairwise6_op$contrast <- str_replace_all(pairwise6_op$contrast, " ", "")
pairwise6 <- rbind(pairwise6_ac, pairwise6_tc, pairwise6_np, pairwise6_op)
pairwise6 <- subset(pairwise6, select = -c(1))
pairwise6 <- rename(pairwise6, term="contrast")
val_lab(pairwise6$model) = num_lab("
1 Attacker Copartisan
2 Target Copartisan
3 Non-Partisan
4 Out-Party
")
png("Figure5.png", width = 7, height = 6, units = "in", res = 300)
ggplot(pairwise6, aes(x = term, y = estimate) ) +
geom_point(aes(color = p.value < 0.05)) +
geom_pointrange(aes(ymin = conf.low, ymax = conf.high, color = p.value < 0.05), size = 0.15) +
coord_flip() +
scale_x_discrete(limits=rev) +
geom_hline(yintercept=0, linetype="dashed", color="grey50") +
theme_classic() +
facet_wrap(~model, scales = "fixed", nrow=2, ncol=2, strip.position = "top") +
theme(strip.placement = "outside") +
labs(x = NULL, y = "Favourability (Target)") +
scale_x_discrete(limits=c("Treat1-Treat3","Treat3-Treat2","Treat1-Treat2",
"Treat3-Control", "Treat2-Control", "Treat1-Control"),
breaks=c("Treat1-Treat3","Treat3-Treat2","Treat1-Treat2",
"Treat3-Control", "Treat2-Control", "Treat1-Control"),
labels=c("**Personal Vs**
Both", "**Both Vs**
Policy", "**Personal Vs**
Policy",
"**Both Vs**
Control", "**Policy Vs**
Control", "**Personal Vs**
Control")) +
theme(axis.text.y=element_markdown(size=11.5, color="black"),
axis.title=element_text(size=12),
strip.text = element_text(size = 12, face = "bold")) +
scale_color_manual(values = c("TRUE" = "black", "FALSE" = "darkgrey"), guide="none"
)
dev.off()
# Export results as table with main stats
treatment_order <- c("Treat1-Control", "Treat2-Control", "Treat3-Control",
"Treat1-Treat2", "Treat3-Treat2", "Treat1-Treat3")
pairwise6$term <- factor(pairwise6$term, levels = treatment_order)
pairwise6 <- pairwise6[,c(1, 3:4, 6:11)]
pairwise6 <- pairwise6 %>%
arrange(model, term)
colnames(pairwise6) <- c("Treatment", "Estimate", "Std Error", "95% CI Lower", "95% CI Upper", "t stat", "p-value", "Model", "N")
pairwise6 <- pairwise6 %>%
mutate(Treatment = case_when(
Treatment == "Treat1-Control" ~ "Personal-Control",
Treatment == "Treat2-Control" ~ "Policy-Control",
Treatment == "Treat3-Control" ~ "Both-Control",
Treatment == "Treat1-Treat2" ~ "Personal-Policy",
Treatment == "Treat3-Treat2" ~ "Both-Policy",
TRUE ~ "Personal-Both"
))
html_table <- pairwise6 %>%
gt() %>%
fmt_number(
columns = "p-value",
decimals = 5
) %>%
fmt_number(
columns = c("Estimate", "Std Error", "95% CI Lower", "95% CI Upper", "t stat"),
decimals = 2
) %>%
tab_style(
style = cell_text(weight = "bold"),
locations = cells_body(
columns = everything(),
rows = `p-value` < 0.05
)
)
html_table |> gtsave("table_S8.docx", type = "docx")
# Export Figure 2
pairwise1$model <- 1
pairwise3$model <- 2
pairwise5$model <- 3
figure2 <- rbind(pairwise1, pairwise3, pairwise5)
val_lab(figure2$model) = num_lab("
1 Degree of Negativity (Attacker)
2 Favourability (Attacker)
3 Favourability (Target)
")
png("Figure2.png", width = 7, height = 4.2, units = "in", res = 300)
ggplot(figure2, aes(contrast, estimate)) +
geom_point(aes(color = p.value < 0.05)) +
geom_pointrange(aes(ymin = conf.low, ymax = conf.high, color = p.value < 0.05), size = 0.15) +
coord_flip() +
scale_x_discrete(limits=rev) +
geom_hline(yintercept=0, linetype="dashed", color="grey50") +
theme_classic() +
facet_wrap(~model, labeller = label_wrap_gen(width=22)) +
labs(x = NULL, y = "") +
scale_x_discrete(limits=c("Treat1 - Treat3","Treat3 - Treat2","Treat1 - Treat2",
"Treat3 - Control", "Treat2 - Control", "Treat1 - Control"),
breaks=c("Treat1 - Treat3","Treat3 - Treat2","Treat1 - Treat2",
"Treat3 - Control", "Treat2 - Control", "Treat1 - Control"),
labels=c("**Personal Vs**
Both", "**Both Vs**
Policy", "**Personal Vs**
Policy",
"**Both Vs**
Control", "**Policy Vs**
Control", "**Personal Vs**
Control")) +
ylim(-1.25, 2.25) +
theme(axis.text.y=element_markdown(size=12, color="black"),
axis.title=element_text(size=12),
strip.text = element_text(size = 12, face = "bold")) +
scale_color_manual(values = c("TRUE" = "black", "FALSE" = "darkgrey"), guide="none"
)
dev.off()
# Export results as table with main stats
figure2 <- figure2[,-1]
figure2 <- rename(figure2, term="contrast")
figure2$term <- str_replace_all(figure2$term, " ", "")
treatment_order <- c("Treat1-Control", "Treat2-Control", "Treat3-Control",
"Treat1-Treat2", "Treat3-Treat2", "Treat1-Treat3")
figure2$term <- factor(figure2$term, levels = treatment_order)
figure2 <- figure2[,c(1, 3:4, 6:9, 11)]
figure2$N <- 1664
figure2 <- figure2 %>%
arrange(model, term)
figure2 <- figure2 %>%
mutate(p.value = round(p.value, 5))
colnames(figure2) <- c("Treatment", "Estimate", "Std Error", "95% CI Lower", "95% CI Upper", "t stat", "p-value", "Model", "N")
figure2 <- figure2 %>%
mutate(Treatment = case_when(
Treatment == "Treat1-Control" ~ "Personal-Control",
Treatment == "Treat2-Control" ~ "Policy-Control",
Treatment == "Treat3-Control" ~ "Both-Control",
Treatment == "Treat1-Treat2" ~ "Personal-Policy",
Treatment == "Treat3-Treat2" ~ "Both-Policy",
TRUE ~ "Personal-Both"
))
html_table <- figure2 %>%
gt() %>%
fmt_number(
columns = "p-value",
decimals = 5
) %>%
fmt_number(
columns = c("Estimate", "Std Error", "95% CI Lower", "95% CI Upper", "t stat"),
decimals = 2
) %>%
tab_style(
style = cell_text(weight = "bold"),
locations = cells_body(
columns = everything(),
rows = `p-value` < 0.05
)
)
html_table |> gtsave("table_S5.docx", type = "docx")
# Distribution for favourability variables in control group
control <- subset(yougov3, pooled_groups=="Control")
control <- control[, c(53:54)]
summary(control$Q1_fav_attacker)
summary(control$Q1_fav_target)
mode <- function(x) {
uniq_x <- unique(x)
uniq_x[which.max(tabulate(match(x, uniq_x)))]
}
mode(control$Q1_fav_attacker)
mode(control$Q1_fav_target)
# Recast social class variable
yougov3 <- yougov3 %>%
mutate(social_grade = case_when(
profile_socialgrade_cie %in% c("A", "B", "C1") ~ "High",
profile_socialgrade_cie %in% c("C2", "D", "E") ~ "Low",
TRUE ~ NA_character_
))
yougov3$social_grade <- factor(yougov3$social_grade,
levels = c("High", "Low"),
ordered = TRUE)
# Social class analysis
reg7 <- lm(Q4_neg1 ~ pooled_groups*social_grade, data=yougov3, weights = yougov3$weight)
summary(reg7)
pairwise7_def <- pairs(emmeans(reg7, ~ pooled_groups*social_grade), adjust = "none")
pairwise7_rev <- pairs(emmeans(reg7, ~ pooled_groups*social_grade), reverse = TRUE, adjust = "none")
pairwise7_def <- tidy(pairwise7_def, conf.int = TRUE)
pairwise7_rev <- tidy(pairwise7_rev, conf.int = TRUE)
pairwise7_def_high <- pairwise7_def[c(8,9),]
pairwise7_rev_high <- pairwise7_rev[c(1,2,4,6),]
pairwise7_high <- rbind(pairwise7_rev_high, pairwise7_def_high)
pairwise7_high$model <- 1
pairwise7_high$N <- 922
pairwise7_high$order <- c(1,2,3,5,4,6)
pairwise7_high$contrast <- str_replace_all(pairwise7_high$contrast, "High", "")
pairwise7_high$contrast <- str_replace_all(pairwise7_high$contrast, " ", "")
pairwise7_def_low <- pairwise7_def[c(26,27),]
pairwise7_rev_low <- pairwise7_rev[c(15,20,26,28),]
pairwise7_low <- rbind(pairwise7_rev_low, pairwise7_def_low)
pairwise7_low$model <- 2
pairwise7_low$N <- 720
pairwise7_low$order <- c(1,2,3,5,4,6)
pairwise7_low$contrast <- str_replace_all(pairwise7_low$contrast, "Low", "")
pairwise7_low$contrast <- str_replace_all(pairwise7_low$contrast, " ", "")
pairwise7 <- rbind(pairwise7_high, pairwise7_low)
pairwise7 <- subset(pairwise7, select = -c(1))
pairwise7 <- rename(pairwise7, term="contrast")
val_lab(pairwise7$model) = num_lab("
1 ABC1
2 C2DE
")
pdf("Figure_S10.pdf", width = 7, height = 4.2)
ggplot(pairwise7, aes(x = term, y = estimate) ) +
geom_point(aes(color = p.value < 0.05)) +
geom_pointrange(aes(ymin = conf.low, ymax = conf.high, color = p.value < 0.05), size = 0.15) +
coord_flip() +
scale_x_discrete(limits=rev) +
geom_hline(yintercept=0, linetype="dashed", color="grey50") +
theme_classic() +
facet_wrap(~model, scales = "fixed", nrow=2, ncol=2, strip.position = "top") +
theme(strip.placement = "outside") +
labs(x = NULL, y = "Degree of negativity (Attacker)") +
scale_x_discrete(limits=c("Treat1-Treat3","Treat3-Treat2","Treat1-Treat2",
"Treat3-Control", "Treat2-Control", "Treat1-Control"),
breaks=c("Treat1-Treat3","Treat3-Treat2","Treat1-Treat2",
"Treat3-Control", "Treat2-Control", "Treat1-Control"),
labels=c("**Personal Vs**
Both", "**Both Vs**
Policy", "**Personal Vs**
Policy",
"**Both Vs**
Control", "**Policy Vs**
Control", "**Personal Vs**
Control")) +
theme(axis.text.y=element_markdown(size=11.5, color="black"),
axis.title=element_text(size=12),
strip.text = element_text(size = 12, face = "bold")) +
scale_color_manual(values = c("TRUE" = "black", "FALSE" = "darkgrey"), guide="none"
)
dev.off()
reg8 <- lm(Q1_fav_attacker ~ pooled_groups*social_grade, data=yougov3, weights = yougov3$weight)
summary(reg8)
pairwise8_def <- pairs(emmeans(reg8, ~ pooled_groups*social_grade), adjust = "none")
pairwise8_rev <- pairs(emmeans(reg8, ~ pooled_groups*social_grade), reverse = TRUE, adjust = "none")
pairwise8_def <- tidy(pairwise8_def, conf.int = TRUE)
pairwise8_rev <- tidy(pairwise8_rev, conf.int = TRUE)
pairwise8_def_high <- pairwise8_def[c(8,9),]
pairwise8_rev_high <- pairwise8_rev[c(1,2,4,6),]
pairwise8_high <- rbind(pairwise8_rev_high, pairwise8_def_high)
pairwise8_high$model <- 1
pairwise8_high$N <- 922
pairwise8_high$order <- c(1,2,3,5,4,6)
pairwise8_high$contrast <- str_replace_all(pairwise8_high$contrast, "High", "")
pairwise8_high$contrast <- str_replace_all(pairwise8_high$contrast, " ", "")
pairwise8_def_low <- pairwise8_def[c(26,27),]
pairwise8_rev_low <- pairwise8_rev[c(15,20,26,28),]
pairwise8_low <- rbind(pairwise8_rev_low, pairwise8_def_low)
pairwise8_low$model <- 2
pairwise8_low$N <- 720
pairwise8_low$order <- c(1,2,3,5,4,6)
pairwise8_low$contrast <- str_replace_all(pairwise8_low$contrast, "Low", "")
pairwise8_low$contrast <- str_replace_all(pairwise8_low$contrast, " ", "")
pairwise8 <- rbind(pairwise8_high, pairwise8_low)
pairwise8 <- subset(pairwise8, select = -c(1))
pairwise8 <- rename(pairwise8, term="contrast")
val_lab(pairwise8$model) = num_lab("
1 ABC1
2 C2DE
")
pdf("Figure_S11.pdf", width = 7, height = 4.2)
ggplot(pairwise8, aes(x = term, y = estimate) ) +
geom_point(aes(color = p.value < 0.05)) +
geom_pointrange(aes(ymin = conf.low, ymax = conf.high, color = p.value < 0.05), size = 0.15) +
coord_flip() +
scale_x_discrete(limits=rev) +
geom_hline(yintercept=0, linetype="dashed", color="grey50") +
theme_classic() +
facet_wrap(~model, scales = "fixed", nrow=2, ncol=2, strip.position = "top") +
theme(strip.placement = "outside") +
labs(x = NULL, y = "Favourability (Attacker)") +
scale_x_discrete(limits=c("Treat1-Treat3","Treat3-Treat2","Treat1-Treat2",
"Treat3-Control", "Treat2-Control", "Treat1-Control"),
breaks=c("Treat1-Treat3","Treat3-Treat2","Treat1-Treat2",
"Treat3-Control", "Treat2-Control", "Treat1-Control"),
labels=c("**Personal Vs**
Both", "**Both Vs**
Policy", "**Personal Vs**
Policy",
"**Both Vs**
Control", "**Policy Vs**
Control", "**Personal Vs**
Control")) +
theme(axis.text.y=element_markdown(size=11.5, color="black"),
axis.title=element_text(size=12),
strip.text = element_text(size = 12, face = "bold")) +
scale_color_manual(values = c("TRUE" = "black", "FALSE" = "darkgrey"), guide="none"
)
dev.off()
reg9 <- lm(Q1_fav_target ~ pooled_groups*social_grade, data=yougov3, weights = yougov3$weight)
summary(reg9)
pairwise9_def <- pairs(emmeans(reg9, ~ pooled_groups*social_grade), adjust = "none")
pairwise9_rev <- pairs(emmeans(reg9, ~ pooled_groups*social_grade), reverse = TRUE, adjust = "none")
pairwise9_def <- tidy(pairwise9_def, conf.int = TRUE)
pairwise9_rev <- tidy(pairwise9_rev, conf.int = TRUE)
pairwise9_def_high <- pairwise9_def[c(8,9),]
pairwise9_rev_high <- pairwise9_rev[c(1,2,4,6),]
pairwise9_high <- rbind(pairwise9_rev_high, pairwise9_def_high)
pairwise9_high$model <- 1
pairwise9_high$N <- 922
pairwise9_high$order <- c(1,2,3,5,4,6)
pairwise9_high$contrast <- str_replace_all(pairwise9_high$contrast, "High", "")
pairwise9_high$contrast <- str_replace_all(pairwise9_high$contrast, " ", "")
pairwise9_def_low <- pairwise9_def[c(26,27),]
pairwise9_rev_low <- pairwise9_rev[c(15,20,26,28),]
pairwise9_low <- rbind(pairwise9_rev_low, pairwise9_def_low)
pairwise9_low$model <- 2
pairwise9_low$N <- 720
pairwise9_low$order <- c(1,2,3,5,4,6)
pairwise9_low$contrast <- str_replace_all(pairwise9_low$contrast, "Low", "")
pairwise9_low$contrast <- str_replace_all(pairwise9_low$contrast, " ", "")
pairwise9 <- rbind(pairwise9_high, pairwise9_low)
pairwise9 <- subset(pairwise9, select = -c(1))
pairwise9 <- rename(pairwise9, term="contrast")
val_lab(pairwise9$model) = num_lab("
1 ABC1
2 C2DE
")
pdf("Figure_S12.pdf", width = 7, height = 4.2)
ggplot(pairwise9, aes(x = term, y = estimate) ) +
geom_point(aes(color = p.value < 0.05)) +
geom_pointrange(aes(ymin = conf.low, ymax = conf.high, color = p.value < 0.05), size = 0.15) +
coord_flip() +
scale_x_discrete(limits=rev) +
geom_hline(yintercept=0, linetype="dashed", color="grey50") +
theme_classic() +
facet_wrap(~model, scales = "fixed", nrow=2, ncol=2, strip.position = "top") +
theme(strip.placement = "outside") +
labs(x = NULL, y = "Favourability (Target)") +
scale_x_discrete(limits=c("Treat1-Treat3","Treat3-Treat2","Treat1-Treat2",
"Treat3-Control", "Treat2-Control", "Treat1-Control"),
breaks=c("Treat1-Treat3","Treat3-Treat2","Treat1-Treat2",
"Treat3-Control", "Treat2-Control", "Treat1-Control"),
labels=c("**Personal Vs**
Both", "**Both Vs**
Policy", "**Personal Vs**
Policy",
"**Both Vs**
Control", "**Policy Vs**
Control", "**Personal Vs**
Control")) +
theme(axis.text.y=element_markdown(size=11.5, color="black"),
axis.title=element_text(size=12),
strip.text = element_text(size = 12, face = "bold")) +
scale_color_manual(values = c("TRUE" = "black", "FALSE" = "darkgrey"), guide="none"
)
dev.off()
# Recast education variable
yougov3 <- yougov3 %>%
mutate(education = case_when(
highest_education_gce %in% c("Degree") ~ "Degree",
is.na(highest_education_gce) ~ NA,
TRUE ~ "No Degree"
))
yougov3$education <- factor(yougov3$education,
levels = c("Degree", "No Degree"),
ordered = TRUE)
# Education analysis
reg10 <- lm(Q4_neg1 ~ pooled_groups*education, data=yougov3, weights = yougov3$weight)
summary(reg10)
pairwise10_def <- pairs(emmeans(reg10, ~ pooled_groups*education), adjust = "none")
pairwise10_rev <- pairs(emmeans(reg10, ~ pooled_groups*education), reverse = TRUE, adjust = "none")
pairwise10_def <- tidy(pairwise10_def, conf.int = TRUE)
pairwise10_rev <- tidy(pairwise10_rev, conf.int = TRUE)
pairwise10_def_high <- pairwise10_def[c(8,9),]
pairwise10_rev_high <- pairwise10_rev[c(1,2,4,6),]
pairwise10_high <- rbind(pairwise10_rev_high, pairwise10_def_high)
pairwise10_high$model <- 1
pairwise10_high$N <- 486
pairwise10_high$order <- c(1,2,3,5,4,6)
pairwise10_high$contrast <- str_replace_all(pairwise10_high$contrast, "Degree", "")
pairwise10_high$contrast <- str_replace_all(pairwise10_high$contrast, " ", "")
pairwise10_def_low <- pairwise10_def[c(26,27),]
pairwise10_rev_low <- pairwise10_rev[c(15,20,26,28),]
pairwise10_low <- rbind(pairwise10_rev_low, pairwise10_def_low)
pairwise10_low$model <- 2
pairwise10_low$N <- 1177
pairwise10_low$order <- c(1,2,3,5,4,6)
pairwise10_low$contrast <- str_replace_all(pairwise10_low$contrast, "No Degree", "")
pairwise10_low$contrast <- str_replace_all(pairwise10_low$contrast, " ", "")
pairwise10 <- rbind(pairwise10_high, pairwise10_low)
pairwise10 <- subset(pairwise10, select = -c(1))
pairwise10 <- rename(pairwise10, term="contrast")
val_lab(pairwise10$model) = num_lab("
1 Degree
2 No Degree
")
pdf("Figure_S13.pdf", width = 7, height = 4.2)
ggplot(pairwise10, aes(x = term, y = estimate) ) +
geom_point(aes(color = p.value < 0.05)) +
geom_pointrange(aes(ymin = conf.low, ymax = conf.high, color = p.value < 0.05), size = 0.15) +
coord_flip() +
scale_x_discrete(limits=rev) +
geom_hline(yintercept=0, linetype="dashed", color="grey50") +
theme_classic() +
facet_wrap(~model, scales = "fixed", nrow=2, ncol=2, strip.position = "top") +
theme(strip.placement = "outside") +
labs(x = NULL, y = "Degree of negativity (Attacker)") +
scale_x_discrete(limits=c("Treat1-Treat3","Treat3-Treat2","Treat1-Treat2",
"Treat3-Control", "Treat2-Control", "Treat1-Control"),
breaks=c("Treat1-Treat3","Treat3-Treat2","Treat1-Treat2",
"Treat3-Control", "Treat2-Control", "Treat1-Control"),
labels=c("**Personal Vs**
Both", "**Both Vs**
Policy", "**Personal Vs**
Policy",
"**Both Vs**
Control", "**Policy Vs**
Control", "**Personal Vs**
Control")) +
theme(axis.text.y=element_markdown(size=11.5, color="black"),
axis.title=element_text(size=12),
strip.text = element_text(size = 12, face = "bold")) +
scale_color_manual(values = c("TRUE" = "black", "FALSE" = "darkgrey"), guide="none"
)
dev.off()
reg11 <- lm(Q1_fav_attacker ~ pooled_groups*education, data=yougov3, weights = yougov3$weight)
summary(reg11)
pairwise11_def <- pairs(emmeans(reg11, ~ pooled_groups*education), adjust = "none")
pairwise11_rev <- pairs(emmeans(reg11, ~ pooled_groups*education), reverse = TRUE, adjust = "none")
pairwise11_def <- tidy(pairwise11_def, conf.int = TRUE)
pairwise11_rev <- tidy(pairwise11_rev, conf.int = TRUE)
pairwise11_def_high <- pairwise11_def[c(8,9),]
pairwise11_rev_high <- pairwise11_rev[c(1,2,4,6),]
pairwise11_high <- rbind(pairwise11_rev_high, pairwise11_def_high)
pairwise11_high$model <- 1
pairwise11_high$N <- 486
pairwise11_high$order <- c(1,2,3,5,4,6)
pairwise11_high$contrast <- str_replace_all(pairwise11_high$contrast, "Degree", "")
pairwise11_high$contrast <- str_replace_all(pairwise11_high$contrast, " ", "")
pairwise11_def_low <- pairwise11_def[c(26,27),]
pairwise11_rev_low <- pairwise11_rev[c(15,20,26,28),]
pairwise11_low <- rbind(pairwise11_rev_low, pairwise11_def_low)
pairwise11_low$model <- 2
pairwise11_low$N <- 1177
pairwise11_low$order <- c(1,2,3,5,4,6)
pairwise11_low$contrast <- str_replace_all(pairwise11_low$contrast, "No Degree", "")
pairwise11_low$contrast <- str_replace_all(pairwise11_low$contrast, " ", "")
pairwise11 <- rbind(pairwise11_high, pairwise11_low)
pairwise11 <- subset(pairwise11, select = -c(1))
pairwise11 <- rename(pairwise11, term="contrast")
val_lab(pairwise11$model) = num_lab("
1 Degree
2 No Degree
")
pdf("Figure_S14.pdf", width = 7, height = 4.2)
ggplot(pairwise11, aes(x = term, y = estimate) ) +
geom_point(aes(color = p.value < 0.05)) +
geom_pointrange(aes(ymin = conf.low, ymax = conf.high, color = p.value < 0.05), size = 0.15) +
coord_flip() +
scale_x_discrete(limits=rev) +
geom_hline(yintercept=0, linetype="dashed", color="grey50") +
theme_classic() +
facet_wrap(~model, scales = "fixed", nrow=2, ncol=2, strip.position = "top") +
theme(strip.placement = "outside") +
labs(x = NULL, y = "Favourability (Attacker)") +
scale_x_discrete(limits=c("Treat1-Treat3","Treat3-Treat2","Treat1-Treat2",
"Treat3-Control", "Treat2-Control", "Treat1-Control"),
breaks=c("Treat1-Treat3","Treat3-Treat2","Treat1-Treat2",
"Treat3-Control", "Treat2-Control", "Treat1-Control"),
labels=c("**Personal Vs**
Both", "**Both Vs**
Policy", "**Personal Vs**
Policy",
"**Both Vs**
Control", "**Policy Vs**
Control", "**Personal Vs**
Control")) +
theme(axis.text.y=element_markdown(size=11.5, color="black"),
axis.title=element_text(size=12),
strip.text = element_text(size = 12, face = "bold")) +
scale_color_manual(values = c("TRUE" = "black", "FALSE" = "darkgrey"), guide="none"
)
dev.off()
reg12 <- lm(Q1_fav_target ~ pooled_groups*education, data=yougov3, weights = yougov3$weight)
summary(reg12)
pairwise12_def <- pairs(emmeans(reg12, ~ pooled_groups*education), adjust = "none")
pairwise12_rev <- pairs(emmeans(reg12, ~ pooled_groups*education), reverse = TRUE, adjust = "none")
pairwise12_def <- tidy(pairwise12_def, conf.int = TRUE)
pairwise12_rev <- tidy(pairwise12_rev, conf.int = TRUE)
pairwise12_def_high <- pairwise12_def[c(8,9),]
pairwise12_rev_high <- pairwise12_rev[c(1,2,4,6),]
pairwise12_high <- rbind(pairwise12_rev_high, pairwise12_def_high)
pairwise12_high$model <- 1
pairwise12_high$N <- 486
pairwise12_high$order <- c(1,2,3,5,4,6)
pairwise12_high$contrast <- str_replace_all(pairwise12_high$contrast, "Degree", "")
pairwise12_high$contrast <- str_replace_all(pairwise12_high$contrast, " ", "")
pairwise12_def_low <- pairwise12_def[c(26,27),]
pairwise12_rev_low <- pairwise12_rev[c(15,20,26,28),]
pairwise12_low <- rbind(pairwise12_rev_low, pairwise12_def_low)
pairwise12_low$model <- 2
pairwise12_low$N <- 1177
pairwise12_low$order <- c(1,2,3,5,4,6)
pairwise12_low$contrast <- str_replace_all(pairwise12_low$contrast, "No Degree", "")
pairwise12_low$contrast <- str_replace_all(pairwise12_low$contrast, " ", "")
pairwise12 <- rbind(pairwise12_high, pairwise12_low)
pairwise12 <- subset(pairwise12, select = -c(1))
pairwise12 <- rename(pairwise12, term="contrast")
val_lab(pairwise12$model) = num_lab("
1 Degree
2 No Degree
")
pdf("Figure_S15.pdf", width = 7, height = 4.2)
ggplot(pairwise12, aes(x = term, y = estimate) ) +
geom_point(aes(color = p.value < 0.05)) +
geom_pointrange(aes(ymin = conf.low, ymax = conf.high, color = p.value < 0.05), size = 0.15) +
coord_flip() +
scale_x_discrete(limits=rev) +
geom_hline(yintercept=0, linetype="dashed", color="grey50") +
theme_classic() +
facet_wrap(~model, scales = "fixed", nrow=2, ncol=2, strip.position = "top") +
theme(strip.placement = "outside") +
labs(x = NULL, y = "Favourability (Target)") +
scale_x_discrete(limits=c("Treat1-Treat3","Treat3-Treat2","Treat1-Treat2",
"Treat3-Control", "Treat2-Control", "Treat1-Control"),
breaks=c("Treat1-Treat3","Treat3-Treat2","Treat1-Treat2",
"Treat3-Control", "Treat2-Control", "Treat1-Control"),
labels=c("**Personal Vs**
Both", "**Both Vs**
Policy", "**Personal Vs**
Policy",
"**Both Vs**
Control", "**Policy Vs**
Control", "**Personal Vs**
Control")) +
theme(axis.text.y=element_markdown(size=11.5, color="black"),
axis.title=element_text(size=12),
strip.text = element_text(size = 12, face = "bold")) +
scale_color_manual(values = c("TRUE" = "black", "FALSE" = "darkgrey"), guide="none"
)
dev.off()
# Robustness test with copartisan and out-party/non-partisan categories
partisan_data <- subset(yougov3, !is.na(partisan))
partisan_data$partisan_alt <-
case_when(
partisan_data$partyid_2017 == "Labour" & partisan_data$attacker == "labour" ~ "Copartisan",
partisan_data$partyid_2017 == "Conservative" & partisan_data$attacker == "tory" ~ "Copartisan",
partisan_data$partyid_2017 == "Labour" & partisan_data$target == "labour" ~ "Copartisan",
partisan_data$partyid_2017 == "Conservative" & partisan_data$target == "tory" ~ "Copartisan",
is.na(partisan_data$partyid_2017) ~ NA_character_,
TRUE ~ "Out-party/Non-partisan")
reg13 <- lm(Q1_fav_target ~ pooled_groups*partisan_alt, data=partisan_data, weights = partisan_data$weight)
summary(reg13)
pairwise13_def <- pairs(emmeans(reg13, ~ pooled_groups*partisan_alt), adjust = "none")
pairwise13_rev <- pairs(emmeans(reg13, ~ pooled_groups*partisan_alt), reverse = TRUE, adjust = "none")
pairwise13_def <- tidy(pairwise13_def, conf.int = TRUE)
pairwise13_rev <- tidy(pairwise13_rev, conf.int = TRUE)
pairwise13_def_cop <- pairwise13_def[c(8,9),]
pairwise13_rev_cop <- pairwise13_rev[c(1,2,4,6),]
pairwise13_cop <- rbind(pairwise13_rev_cop, pairwise13_def_cop)
pairwise13_cop$model <- 1
pairwise13_cop$order <- c(1,2,3,5,4,6)
pairwise13_cop$contrast <- str_replace_all(pairwise13_cop$contrast, "Copartisan", "")
pairwise13_cop$contrast <- str_replace_all(pairwise13_cop$contrast, " ", "")
pairwise13_def_noncop <- pairwise13_def[c(26,27),]
pairwise13_rev_noncop <- pairwise13_rev[c(15,20,26,28),]
pairwise13_noncop <- rbind(pairwise13_rev_noncop, pairwise13_def_noncop)
pairwise13_noncop$model <- 2
pairwise13_noncop$order <- c(1,2,3,5,4,6)
pairwise13_noncop$contrast <- str_replace_all(pairwise13_noncop$contrast, "Out-party/Non-partisan", "")
pairwise13_noncop$contrast <- gsub("[][(]", "", pairwise13_noncop$contrast)
pairwise13_noncop$contrast <- gsub("[][)]", "", pairwise13_noncop$contrast)
pairwise13_noncop$contrast <- str_replace_all(pairwise13_noncop$contrast, " ", "")
pairwise13 <- rbind(pairwise13_cop, pairwise13_noncop)
pairwise13 <- subset(pairwise13, select = -c(1))
pairwise13 <- rename(pairwise13, term="contrast")
val_lab(pairwise13$model) = num_lab("
1 Copartisan
2 Out-party/Non-partisan
")
pdf("Figure_S9.pdf", width = 7, height = 4.2)
ggplot(pairwise13, aes(x = term, y = estimate) ) +
geom_point(aes(color = p.value < 0.05)) +
geom_pointrange(aes(ymin = conf.low, ymax = conf.high, color = p.value < 0.05), size = 0.15) +
coord_flip() +
scale_x_discrete(limits=rev) +
geom_hline(yintercept=0, linetype="dashed", color="grey50") +
theme_classic() +
facet_wrap(~model, scales = "fixed", nrow=2, ncol=2, strip.position = "top") +
theme(strip.placement = "outside") +
labs(x = NULL, y = "Favourability (Target)") +
scale_x_discrete(limits=c("Treat1-Treat3","Treat3-Treat2","Treat1-Treat2",
"Treat3-Control", "Treat2-Control", "Treat1-Control"),
breaks=c("Treat1-Treat3","Treat3-Treat2","Treat1-Treat2",
"Treat3-Control", "Treat2-Control", "Treat1-Control"),
labels=c("**Personal Vs**
Both", "**Both Vs**
Policy", "**Personal Vs**
Policy",
"**Both Vs**
Control", "**Policy Vs**
Control", "**Personal Vs**
Control")) +
theme(axis.text.y=element_markdown(size=11.5, color="black"),
axis.title=element_text(size=12),
strip.text = element_text(size = 12, face = "bold")) +
scale_color_manual(values = c("TRUE" = "black", "FALSE" = "darkgrey"), guide="none"
)
dev.off()
# Calculate statistical power
# Negativity
cohen_d_values <- yougov3 %>%
group_by(pooled_groups) %>%
summarise(
mean_value = mean(Q4_neg1, na.rm = TRUE),
sd_value = sd(Q4_neg1, na.rm = TRUE)
)
pairwise_combinations <- combn(cohen_d_values$pooled_groups, 2, simplify = FALSE)
# Calculate Cohen's d for each pair of groups
cohen_d_results <- lapply(pairwise_combinations, function(groups) {
# Extract means and SDs for the two groups
group_1 <- cohen_d_values %>% filter(pooled_groups == groups[1])
group_2 <- cohen_d_values %>% filter(pooled_groups == groups[2])
# Calculate Cohen's d
cohens_d <- (group_1$mean_value - group_2$mean_value) /
sqrt(((group_1$sd_value^2 + group_2$sd_value^2) / 2))
# Return the result in a data frame
data.frame(
group_1 = groups[1],
group_2 = groups[2],
cohens_d = cohens_d
)
})
# Combine the list into a data frame
cohen_d_results_df <- do.call(rbind, cohen_d_results)
# For each pair, get the sample sizes for the two groups
power_results <- lapply(1:nrow(cohen_d_results_df), function(i) {
group_1 <- cohen_d_results_df$group_1[i]
group_2 <- cohen_d_results_df$group_2[i]
# Extract sample sizes for each group from the original data
n_group_1 <- yougov3 %>% filter(pooled_groups == group_1) %>% summarise(n = n()) %>% pull(n)
n_group_2 <- yougov3 %>% filter(pooled_groups == group_2) %>% summarise(n = n()) %>% pull(n)
# Extract Cohen's d for this pair
cohens_d <- cohen_d_results_df$cohens_d[i]
# Calculate the power for the given effect size (Cohen's d), sample sizes, and alpha
pwr_result <- pwr.t.test(d = cohens_d,
n = max(n_group_1, n_group_2),
sig.level = 0.05,
type = "two.sample",
alternative = "two.sided")
# Return the result in a data frame
data.frame(
group_1 = group_1,
group_2 = group_2,
cohens_d = cohens_d,
power = pwr_result$power,
n_group_1 = n_group_1,
n_group_2 = n_group_2
)
})
# Combine the list into a data frame
power_results_df1 <- do.call(rbind, power_results)
# View the results
print(power_results_df1)
# Favourability (Attacker)
cohen_d_values <- yougov3 %>%
group_by(pooled_groups) %>%
summarise(
mean_value = mean(Q1_fav_attacker, na.rm = TRUE),
sd_value = sd(Q1_fav_attacker, na.rm = TRUE)
)
pairwise_combinations <- combn(cohen_d_values$pooled_groups, 2, simplify = FALSE)
# Calculate Cohen's d for each pair of groups
cohen_d_results <- lapply(pairwise_combinations, function(groups) {
# Extract means and SDs for the two groups
group_1 <- cohen_d_values %>% filter(pooled_groups == groups[1])
group_2 <- cohen_d_values %>% filter(pooled_groups == groups[2])
# Calculate Cohen's d
cohens_d <- (group_1$mean_value - group_2$mean_value) /
sqrt(((group_1$sd_value^2 + group_2$sd_value^2) / 2))
# Return the result in a data frame
data.frame(
group_1 = groups[1],
group_2 = groups[2],
cohens_d = cohens_d
)
})
# Combine the list into a data frame
cohen_d_results_df <- do.call(rbind, cohen_d_results)
# For each pair, get the sample sizes for the two groups
power_results <- lapply(1:nrow(cohen_d_results_df), function(i) {
group_1 <- cohen_d_results_df$group_1[i]
group_2 <- cohen_d_results_df$group_2[i]
# Extract sample sizes for each group from the original data
n_group_1 <- yougov3 %>% filter(pooled_groups == group_1) %>% summarise(n = n()) %>% pull(n)
n_group_2 <- yougov3 %>% filter(pooled_groups == group_2) %>% summarise(n = n()) %>% pull(n)
# Extract Cohen's d for this pair
cohens_d <- cohen_d_results_df$cohens_d[i]
# Calculate the power for the given effect size (Cohen's d), sample sizes, and alpha
pwr_result <- pwr.t.test(d = cohens_d,
n = max(n_group_1, n_group_2),
sig.level = 0.05,
type = "two.sample",
alternative = "two.sided")
# Return the result in a data frame
data.frame(
group_1 = group_1,
group_2 = group_2,
cohens_d = cohens_d,
power = pwr_result$power,
n_group_1 = n_group_1,
n_group_2 = n_group_2
)
})
# Combine the list into a data frame
power_results_df2 <- do.call(rbind, power_results)
# View the results
print(power_results_df2)
# Favourability (Target)
cohen_d_values <- yougov3 %>%
group_by(pooled_groups) %>%
summarise(
mean_value = mean(Q1_fav_target, na.rm = TRUE),
sd_value = sd(Q1_fav_target, na.rm = TRUE)
)
pairwise_combinations <- combn(cohen_d_values$pooled_groups, 2, simplify = FALSE)
# Calculate Cohen's d for each pair of groups
cohen_d_results <- lapply(pairwise_combinations, function(groups) {
# Extract means and SDs for the two groups
group_1 <- cohen_d_values %>% filter(pooled_groups == groups[1])
group_2 <- cohen_d_values %>% filter(pooled_groups == groups[2])
# Calculate Cohen's d
cohens_d <- (group_1$mean_value - group_2$mean_value) /
sqrt(((group_1$sd_value^2 + group_2$sd_value^2) / 2))
# Return the result in a data frame
data.frame(
group_1 = groups[1],
group_2 = groups[2],
cohens_d = cohens_d
)
})
# Combine the list into a data frame
cohen_d_results_df <- do.call(rbind, cohen_d_results)
# For each pair, get the sample sizes for the two groups
power_results <- lapply(1:nrow(cohen_d_results_df), function(i) {
group_1 <- cohen_d_results_df$group_1[i]
group_2 <- cohen_d_results_df$group_2[i]
# Extract sample sizes for each group from the original data
n_group_1 <- yougov3 %>% filter(pooled_groups == group_1) %>% summarise(n = n()) %>% pull(n)
n_group_2 <- yougov3 %>% filter(pooled_groups == group_2) %>% summarise(n = n()) %>% pull(n)
# Extract Cohen's d for this pair
cohens_d <- cohen_d_results_df$cohens_d[i]
# Calculate the power for the given effect size (Cohen's d), sample sizes, and alpha
pwr_result <- pwr.t.test(d = cohens_d,
n = max(n_group_1, n_group_2),
sig.level = 0.05,
type = "two.sample",
alternative = "two.sided")
# Return the result in a data frame
data.frame(
group_1 = group_1,
group_2 = group_2,
cohens_d = cohens_d,
power = pwr_result$power,
n_group_1 = n_group_1,
n_group_2 = n_group_2
)
})
# Combine the list into a data frame
power_results_df3 <- do.call(rbind, power_results)
# View the results
print(power_results_df3)
# Partisanship data
# Negativity
cohen_d_values <- partisan_data %>%
group_by(pooled_groups) %>%
summarise(
mean_value = mean(Q4_neg1, na.rm = TRUE),
sd_value = sd(Q4_neg1, na.rm = TRUE)
)
pairwise_combinations <- combn(cohen_d_values$pooled_groups, 2, simplify = FALSE)
# Calculate Cohen's d for each pair of groups
cohen_d_results <- lapply(pairwise_combinations, function(groups) {
# Extract means and SDs for the two groups
group_1 <- cohen_d_values %>% filter(pooled_groups == groups[1])
group_2 <- cohen_d_values %>% filter(pooled_groups == groups[2])
# Calculate Cohen's d
cohens_d <- (group_1$mean_value - group_2$mean_value) /
sqrt(((group_1$sd_value^2 + group_2$sd_value^2) / 2))
# Return the result in a data frame
data.frame(
group_1 = groups[1],
group_2 = groups[2],
cohens_d = cohens_d
)
})
# Combine the list into a data frame
cohen_d_results_df <- do.call(rbind, cohen_d_results)
# For each pair, get the sample sizes for the two groups
power_results <- lapply(1:nrow(cohen_d_results_df), function(i) {
group_1 <- cohen_d_results_df$group_1[i]
group_2 <- cohen_d_results_df$group_2[i]
# Extract sample sizes for each group from the original data
n_group_1 <- partisan_data %>% filter(pooled_groups == group_1) %>% summarise(n = n()) %>% pull(n)
n_group_2 <- partisan_data %>% filter(pooled_groups == group_2) %>% summarise(n = n()) %>% pull(n)
# Extract Cohen's d for this pair
cohens_d <- cohen_d_results_df$cohens_d[i]
# Calculate the power for the given effect size (Cohen's d), sample sizes, and alpha
pwr_result <- pwr.t.test(d = cohens_d,
n = max(n_group_1, n_group_2),
sig.level = 0.05,
type = "two.sample",
alternative = "two.sided")
# Return the result in a data frame
data.frame(
group_1 = group_1,
group_2 = group_2,
cohens_d = cohens_d,
power = pwr_result$power,
n_group_1 = n_group_1,
n_group_2 = n_group_2
)
})
# Combine the list into a data frame
power_results_df4 <- do.call(rbind, power_results)
# View the results
print(power_results_df4)
# Favourability (Attacker)
cohen_d_values <- partisan_data %>%
group_by(pooled_groups) %>%
summarise(
mean_value = mean(Q1_fav_attacker, na.rm = TRUE),
sd_value = sd(Q1_fav_attacker, na.rm = TRUE)
)
pairwise_combinations <- combn(cohen_d_values$pooled_groups, 2, simplify = FALSE)
# Calculate Cohen's d for each pair of groups
cohen_d_results <- lapply(pairwise_combinations, function(groups) {
# Extract means and SDs for the two groups
group_1 <- cohen_d_values %>% filter(pooled_groups == groups[1])
group_2 <- cohen_d_values %>% filter(pooled_groups == groups[2])
# Calculate Cohen's d
cohens_d <- (group_1$mean_value - group_2$mean_value) /
sqrt(((group_1$sd_value^2 + group_2$sd_value^2) / 2))
# Return the result in a data frame
data.frame(
group_1 = groups[1],
group_2 = groups[2],
cohens_d = cohens_d
)
})
# Combine the list into a data frame
cohen_d_results_df <- do.call(rbind, cohen_d_results)
# For each pair, get the sample sizes for the two groups
power_results <- lapply(1:nrow(cohen_d_results_df), function(i) {
group_1 <- cohen_d_results_df$group_1[i]
group_2 <- cohen_d_results_df$group_2[i]
# Extract sample sizes for each group from the original data
n_group_1 <- partisan_data %>% filter(pooled_groups == group_1) %>% summarise(n = n()) %>% pull(n)
n_group_2 <- partisan_data %>% filter(pooled_groups == group_2) %>% summarise(n = n()) %>% pull(n)
# Extract Cohen's d for this pair
cohens_d <- cohen_d_results_df$cohens_d[i]
# Calculate the power for the given effect size (Cohen's d), sample sizes, and alpha
pwr_result <- pwr.t.test(d = cohens_d,
n = max(n_group_1, n_group_2),
sig.level = 0.05,
type = "two.sample",
alternative = "two.sided")
# Return the result in a data frame
data.frame(
group_1 = group_1,
group_2 = group_2,
cohens_d = cohens_d,
power = pwr_result$power,
n_group_1 = n_group_1,
n_group_2 = n_group_2
)
})
# Combine the list into a data frame
power_results_df5 <- do.call(rbind, power_results)
# View the results
print(power_results_df5)
# Favourability (Target)
cohen_d_values <- partisan_data %>%
group_by(pooled_groups) %>%
summarise(
mean_value = mean(Q1_fav_target, na.rm = TRUE),
sd_value = sd(Q1_fav_target, na.rm = TRUE)
)
pairwise_combinations <- combn(cohen_d_values$pooled_groups, 2, simplify = FALSE)
# Calculate Cohen's d for each pair of groups
cohen_d_results <- lapply(pairwise_combinations, function(groups) {
# Extract means and SDs for the two groups
group_1 <- cohen_d_values %>% filter(pooled_groups == groups[1])
group_2 <- cohen_d_values %>% filter(pooled_groups == groups[2])
# Calculate Cohen's d
cohens_d <- (group_1$mean_value - group_2$mean_value) /
sqrt(((group_1$sd_value^2 + group_2$sd_value^2) / 2))
# Return the result in a data frame
data.frame(
group_1 = groups[1],
group_2 = groups[2],
cohens_d = cohens_d
)
})
# Combine the list into a data frame
cohen_d_results_df <- do.call(rbind, cohen_d_results)
# For each pair, get the sample sizes for the two groups
power_results <- lapply(1:nrow(cohen_d_results_df), function(i) {
group_1 <- cohen_d_results_df$group_1[i]
group_2 <- cohen_d_results_df$group_2[i]
# Extract sample sizes for each group from the original data
n_group_1 <- partisan_data %>% filter(pooled_groups == group_1) %>% summarise(n = n()) %>% pull(n)
n_group_2 <- partisan_data %>% filter(pooled_groups == group_2) %>% summarise(n = n()) %>% pull(n)
# Extract Cohen's d for this pair
cohens_d <- cohen_d_results_df$cohens_d[i]
# Calculate the power for the given effect size (Cohen's d), sample sizes, and alpha
pwr_result <- pwr.t.test(d = cohens_d,
n = max(n_group_1, n_group_2),
sig.level = 0.05,
type = "two.sample",
alternative = "two.sided")
# Return the result in a data frame
data.frame(
group_1 = group_1,
group_2 = group_2,
cohens_d = cohens_d,
power = pwr_result$power,
n_group_1 = n_group_1,
n_group_2 = n_group_2
)
})
# Combine the list into a data frame
power_results_df6 <- do.call(rbind, power_results)
# View the results
print(power_results_df6)
# Take power results and export as tables
power_results_df1$model <- 1
power_results_df2$model <- 2
power_results_df3$model <- 3
power_results1 <- rbind(power_results_df1, power_results_df2, power_results_df3)
val_lab(power_results1$model) = num_lab("
1 Negativity
2 Favourability (Attacker)
3 Favourability (Target)
")
# Export results as table
power_results1 <- power_results1 %>%
mutate(cohens_d = round(cohens_d, 3))
power_results1 <- power_results1 %>%
mutate(power = round(power, 2))
power_results1$cohens_d <- format(power_results1$cohens_d, scientific = FALSE)
colnames(power_results1) <- c("Group 1", "Group 2", "Cohen's d", "Power", "N (Group 1)", "N (Group 2)", "Model")
export_table(power_results1, format = "html")
html_table <- export_table(power_results1, format = "html")
html_table |> gtsave("table_S9.docx", type = "docx")
power_results_df4$model <- 1
power_results_df5$model <- 2
power_results_df6$model <- 3
power_results2 <- rbind(power_results_df4, power_results_df5, power_results_df6)
val_lab(power_results2$model) = num_lab("
1 Negativity
2 Favourability (Attacker)
3 Favourability (Target)
")
# Export results as table
power_results2 <- power_results2 %>%
mutate(cohens_d = round(cohens_d, 3))
power_results2 <- power_results2 %>%
mutate(power = round(power, 2))
power_results2$cohens_d <- format(power_results2$cohens_d, scientific = FALSE)
colnames(power_results2) <- c("Group 1", "Group 2", "Cohen's d", "Power", "N (Group 1)", "N (Group 2)", "Model")
export_table(power_results2, format = "html")
html_table <- export_table(power_results2, format = "html")
html_table |> gtsave("table_S10.docx", type = "docx")