############### Incumbency and Query Order (Study 1) ################# ############### Data analysis and graphs ################# #loading packages library(rio) library(psych) library(ggplot2) library(plyr) library(dplyr) library(stats) library(gtable) library(graphics) library(cowplot) library(grid) library(mediation) library(MASS) library(lsr) library(phia) library(multcomp) library(ppcor) #Make sure to first set working directory #setwd("") #importing the data file (transformed in SPSS) data.original <- import("Data Experiment 1.sav", column.labels = TRUE) #having a look at the data set summary(data.original) names(data.original) #filtering the data to get rid of people who didn't finish the survey or who are duplicates data <- filter(data.original, U.S. == 1, PrimaryLast == 1, nmis.SC < 10, nmis.pref < 7) data$pref.ind.1 <- as.numeric(data$pref.ind.1) data$incumbent <- factor(data$incumbent, labels = c("Nickels", "McGinn")) #Demographic information #N summarise(data, n()) #male and female data %>% group_by(gender) %>% summarise(n()) #mean age and standard deviation summarise(data, mean(age)) summarise(data, sd(age)) #number of participants in each condition data %>% group_by(incumbent) %>% summarise(n()) #reliability analyses psych::alpha(data[ ,c("qual.1", "good.1", "person.1", "pref.el.1", "vote.1")]) cor.test(data$other.el.1, data$other.v.1) #familiarty with Grand Rapids, MI dplyr::summarise(data, mean(GrandRap), sd(GrandRap)) #Candidate Preference Information #creating the data for means and standard errors - individual preferences (main text) data %>% group_by(incumbent) %>% dplyr::summarise( individual_preference_mean = mean(pref.ind.1, na.rm = TRUE), individual_preference_SD = sd(pref.ind.1), individual_preference_se = sd(pref.ind.1)/sqrt(n()), other_preference_mean = mean(pref.othr.1, na.rm = TRUE), other_preference_SD = sd(pref.othr.1), other_preference_se = sd(pref.othr.1)/sqrt(n())) -> aggregated aggregated #T-tests: for preferences by incumbent t.test(pref.ind.1 ~ incumbent, data=data) t.test(pref.othr.1 ~ incumbent, data=data, var.equal=TRUE) #supplemental materials #check if these preferencs are significantly different from the midpoint (5) #need to use the recoded measure of candidate preference, where higher scores always mean a preference for the incumbent t.test(data$pref.ind.2, mu=5) summarise(data, inc_mean = mean(pref.ind.2), inc_sd = sd(pref.ind.2)) #check for other's preferences (supplemental materials) t.test(data$pref.othr.2, mu=5, var.equal = false) summarise(data, inc_mean = mean(pref.othr.2), inc_sd = sd(pref.othr.2)) #check to see if there is a content or order effect on candidate preference (supplemental materials) summary(aov(pref.ind.1 ~ incumbent*first* description, data=data)) etaSquared(aov(pref.ind.1 ~ incumbent*first* description, data=data)) #GRAPH - individual preference (main text: Figure 2A) pp_PREF <- ggplot(data = aggregated, aes(x=incumbent, y=individual_preference_mean, fill = incumbent)) + labs(x = NULL, y = "McGinn Preference Nickels") + scale_y_continuous(breaks =1:9, limits = c(1, 9)) + geom_violin(data = data, aes(x = incumbent, y = pref.ind.1, fill = incumbent)) + geom_point(color = "black", position = position_dodge(width = .9)) + geom_errorbar(aes(ymin = individual_preference_mean - individual_preference_se, ymax = individual_preference_mean + individual_preference_se), position = position_dodge(width = .9), width = .1) + scale_fill_manual(values = c("white", "darkgray")) + theme(legend.position="none") + geom_hline(yintercept=5, linetype = 3) + theme(axis.title=element_text(size=10)) pp_PREF #SMDR - Query Order Score #create means and standard errors - SMDR data %>% group_by(incumbent) %>% dplyr::summarise( SMDR_mean = mean(SMDR, na.rm = TRUE), SMDR_SD = sd(SMDR), SMDR_se = sd(SMDR)/sqrt(n())) -> aggregated_1 aggregated_1 #SMDR t'test (main text) t.test(SMDR ~ incumbent, data=data) #controll for display order or content (supplemental materials) summary(aov(SMDR ~ incumbent*first* description, data=data)) etaSquared(aov(SMDR ~ incumbent*first* description, data=data)) #correlations between candidate preference and Query order score cor.test(data$SMDR, data$pref.ind.1) #main text cor.test(data$SMDR, data$pref.othr.1) #supplemental materials #test the partial correlation of SMD and other.preferences while controlling for individual preferences (rule out spill over effect) pcor.test(x = data$SMDR, y = data$pref.othr.1, z = data$pref.ind.1) #SMDR Graph (main text - Figure 2B) pp_SMDR <- ggplot(data = aggregated_1, aes(x=incumbent, y=SMDR_mean, fill = incumbent)) + labs(x = "Incumbent", y = "McGinn First SMDR Nickels First") + geom_violin(data = data, aes(x = incumbent, y = SMDR, fill = incumbent)) + geom_point(color = "black", position = position_dodge(width = .9)) + geom_errorbar(aes(ymin = SMDR_mean - SMDR_se, ymax = SMDR_mean + SMDR_se), position = position_dodge(width = .9), width = .1) + scale_fill_manual(values = c("white", "darkgray")) + theme(legend.position="none") + geom_hline(yintercept=0, linetype = 3) + theme(axis.title=element_text(size=10)) pp_SMDR #Adding two violin plots together (intermediate step) violins <- plot_grid(pp_PREF, pp_SMDR, nrow = 2, align = "v") violins #Scatterplot for the relationship between SMDR and Candidate Preference (main text - Figure 2C) correlation <- cor.test(x= data$pref.ind.1, y = data$SMDR) scatter <- ggplot(data = data, aes(x = SMDR , y = pref.ind.1)) + geom_jitter(alpha =0.45) + labs(x = "McGinn First SMDR Nickels First", y = "McGinn Preference Nickels") + geom_smooth(method=lm, color= "black") + scale_y_continuous(breaks =1:9, limits = c(1, 9)) + scale_x_continuous(breaks = c(-1,-.5,0,.5,1), limits = c(-1, 1)) + annotate("text", x=.5, y=8, label = paste("r (", correlation$parameter ,") =", round(correlation$estimate, 2)))+ geom_hline(yintercept = 5, linetype = 3) + geom_vline(xintercept = 0, linetype = 3) + theme(axis.title=element_text(size=10)) scatter #drawing the entire plot (main Text - Figure 2) ggdraw() + draw_plot(violins, 0, 0,0.5, 1) + draw_plot(scatter, 0.5,0.33,0.5,0.5) + draw_plot_label(c("A", "B", "C"), c(0.45, 0.45, 0.95), c(1, 0.53, 0.88), size = 15) ggplot2::ggsave("Figure 2.eps") #CONTENT OF ASPECTS (Dinner, et al. (2011); main text) hist(data$content) data %>% group_by(incumbent) %>% summarise( mean(content), sd(content)) #correlation betweeen query oder (SMDR) and query content cor.test(data$SMDR, data$content) #is content different per incumbency condition? t.test(content ~ incumbent, data=data) #yay, supports hypothesis - query theory cor.test(data$content, data$pref.ind.1)