#VOTING IN THE RAIN # ########################################## setwd("H:/Writing/2017 Weather/Conjoint/NEU (Marlène)") setwd("N:/IS_MAR/Voting in the rain/TEXT/Local Government Studies/R2") setwd("C:/Users/stadelmann/Desktop/R2") if (!require("pacman", quietly=T)) install.packages("pacman") #### Setup pacman::p_load('dplyr','tidyr','cjoint', 'gsubfn','base', 'stringi', 'lme4') load("cj_VotingRain.RData") # Define Baseline cjLGGLAttr <- list() cjLGGLAttr$Agenda <- "Local public transport" cjLGGLAttr$Costs <- "Some savings" cjLGGLAttr$Outcome <- "Own position probably wins" cjLGGLAttr$Company <- "No company" cjLGGLAttr$Weather <- "Cloudy" ### LMER (without controls) results.PART.engl <- amce.lmer( formula = particip ~ Agenda + Costs + Outcome + Company + Weather, hierarchy = "(1 | id)", baselines = cjLGGLAttr, respondent.id = "id", data = cjLGGL4, na.ignore=T ) results.PART <- plot(results.PART.engl, main = "Attending the Landsgemeinde", xlab = "Change in the propensity to participate") # extract data from figure for further refining results.PART.d <- results.PART$data results.PART.d$x <- seq(1,nrow(results.PART.d), 1) p.cj.general <- ggplot(results.PART.d) + geom_hline(yintercept = 0, size = 0.5, colour = "black", linetype = "dotted") + geom_pointrange(aes(y = pe, ymin = lower, ymax = upper, x = reorder(var, -x)), size=0.4, position=position_dodge(width=0.95)) + ylim(-6,5) + coord_flip() + labs(title="Attending the Landsgemeinde", y="Change in Probability to attend", x="") + theme_minimal() + theme(axis.text.y = element_text(hjust = 0), axis.title.x=element_text(size=11), legend.position="bottom") p.cj.general ggsave("fig2.eps", dpi=300, units=c("in"), width=7, height=4) ggsave("fig2.png", dpi=300, units=c("in"), width=7, height=4) #Participation rate (not shown in the paper) ######################## cjLGGL4$concat <- paste(cjLGGL4$Haupttraktandum,cjLGGL4$Kosten, cjLGGL4$Abstimmungsausgang,cjLGGL4$Begleitung, cjLGGL4$Wetter,sep="_") cjLGGL4$particip01 <- 0 cjLGGL4$particip01[cjLGGL4$particip>95] <- 1 table(cjLGGL4$particip01) Participation <- cjLGGL4 %>% group_by(concat) %>% summarise(mean=mean(particip)) ggplot( Participation,aes(mean)) + geom_density(fill="grey80") + geom_vline(aes(xintercept=0.5), color="grey30", linetype=5) + scale_linetype_manual(values=c(1,2)) + labs(title="Likelihood to participate in the Landsgemeinde", x="Mean probability per scenario", y="Density") + theme_minimal() + theme(legend.position="none") ggsave("meanparticipation.eps", dpi=300, units=c("in"), width=9, height=5) ggsave("meanparticipation.png", dpi=300, units=c("in"), width=9, height=5) ### LMER with interaction between factors #FIGURE 3 ## Voice one's opinion table(cjLGGL4$opinion) cjLGGL4$opinion_d[cjLGGL4$opinion==1] <- 0 cjLGGL4$opinion_d[cjLGGL4$opinion==2] <- 0 cjLGGL4$opinion_d[cjLGGL4$opinion==3] <- 0 cjLGGL4$opinion_d[cjLGGL4$opinion==4] <- 0 cjLGGL4$opinion_d[cjLGGL4$opinion==5] <- 1 cjLGGL4$opinion_d <- as.factor(cjLGGL4$opinion_d) results.PART.opinion.engl <- amce.lmer( formula = particip ~ Agenda:opinion_d + Costs:opinion_d + Outcome:opinion_d + Company:opinion_d + Weather:opinion_d, hierarchy = "(1 | id)", respondent.id = "id", respondent.varying = "opinion_d", baselines = cjLGGLAttr, data = cjLGGL4, na.ignore=T ) summary(results.PART.opinion.engl) results.PART.opinion.engl$cond.estimates results.PART.opinion.engl <- plot(results.PART.opinion.engl, main = "Attending the Landsgemeinde", plot.display = "interaction", xlab = "Change in the propensity to participate") #Extract results results.PART.opinion <- results.PART.opinion.engl$data results.PART.opinion$x <- seq(1,nrow(results.PART.opinion), 1) results.PART.opinion$x2 <- seq(1,(nrow(results.PART.opinion))/2, 1) results.PART.opinion$facet <- recode_factor(results.PART.opinion$facet, 'Conditional on\nClose = 0' = "Meeting opinion less important", 'Conditional on\nClose = 1' = "Meeting opinion important" ) p.opinion <- ggplot(results.PART.opinion) + geom_hline(yintercept = 0, size = 0.5, colour = "black", linetype = "dotted") + geom_pointrange(aes(y = pe, ymin = lower, ymax = upper, x = reorder(var, -x), color=facet, shape=facet), size=0.4, position=position_dodge(width=0.95)) + ylim(-8,5) + coord_flip() + facet_grid(~facet) + labs(title="Attending the Landsgemeinde to voice ones opinion", y="Change in probability to attend", x="", color="Voice ones opinion", shape="Voice ones opinion") + scale_color_brewer(palette="Set1") + theme_minimal() + theme(axis.text.y = element_text(hjust = 0), axis.title.x=element_text(size=11), legend.position="bottom") p.opinion ggsave("fig3_1.eps", dpi=300, units=c("in"), width=8, height=4.5) ggsave("fig3_1.png", dpi=300, units=c("in"), width=8, height=4.5) ##Close race table(cjLGGL4$Outcome) cjLGGL4$Close[cjLGGL4$Outcome=="Close race"] <- 0 cjLGGL4$Close[cjLGGL4$Outcome=="Own position probably wins"] <- 1 cjLGGL4$Close[cjLGGL4$Outcome=="Own position probably loses"] <- 2 cjLGGL4$Close <- as.factor(cjLGGL4$Close) results.PART.close.engl <- amce.lmer( formula = particip ~ Close:Agenda + Close:Costs + Close:Company + Close:Weather, hierarchy = "(1 | id)", respondent.id = "id", respondent.varying = "Close", baselines = cjLGGLAttr, data = cjLGGL4, na.ignore=T ) summary(results.PART.close.engl) results.PART.close.engl$cond.estimates results.PART.close.engl <- plot(results.PART.close.engl, main = "Attending the Landsgemeinde", xlab = "Change in the propensity to participate", plot.display = "interaction") # save the plot data results.PART.close.d <- results.PART.close.engl$data results.PART.close.d$x <- seq(1,nrow(results.PART.close.d), 1) results.PART.close.d$x2 <- seq(1,(nrow(results.PART.close.d))/3, 1) results.PART.close.d$facet <- recode_factor(results.PART.close.d$facet, 'Conditional on\nClose = 0' = "Close", 'Conditional on\nClose = 1' = "Probably winning", 'Conditional on\nClose = 2' = "Probably losing" ) p.close <- ggplot(results.PART.close.d) + geom_hline(yintercept = 0, size = 0.5, colour = "black", linetype = "dotted") + geom_pointrange(aes(y = pe, ymin = lower, ymax = upper, x = reorder(var, -x), color=facet, shape=facet), size=0.4, position=position_dodge(width=0.95)) + ylim(-6.5,6) + coord_flip() + facet_grid(~facet) + labs(title="Attending the Landsgemeinde by closeness of decisions", y="Change in probability to attend", x="", color="Closeness of decisions", shape="Closeness of decisions") + scale_color_brewer(palette="Set1") + theme_minimal() + theme(axis.text.y = element_text(hjust = 0), axis.title.x=element_text(size=11), legend.position="bottom") p.close ggsave("fig3_2.eps", dpi=300, units=c("in"), width=8, height=4) ggsave("fig3_2.png", dpi=300, units=c("in"), width=8, height=4) #FIGURE 4 ##Landsmgeinde as tradition table(cjLGGL4$Tradition) cjLGGL4$Tradition_d[cjLGGL4$Tradition==1] <- 0 cjLGGL4$Tradition_d[cjLGGL4$Tradition==2] <- 0 cjLGGL4$Tradition_d[cjLGGL4$Tradition==3] <- 0 cjLGGL4$Tradition_d[cjLGGL4$Tradition==4] <- 0 cjLGGL4$Tradition_d[cjLGGL4$Tradition==5] <- 1 cjLGGL4$Tradition_d <- as.factor(cjLGGL4$Tradition_d) results.PART.tradition.engl <- amce.lmer( formula = particip ~ Agenda:Tradition_d + Costs:Tradition_d + Outcome:Tradition_d + Company:Tradition_d + Weather:Tradition_d, hierarchy = "(1 | id)", respondent.id = "id", respondent.varying = "Tradition_d", baselines = cjLGGLAttr, data = cjLGGL4, na.ignore=T ) summary(results.PART.tradition.engl) results.PART.tradition.engl$cond.estimates results.PART.tradition <- plot(results.PART.tradition.engl, main = "Attending the Landsgemeinde", plot.display = "interaction", xlab = "Change in the propensity to participate") # save the plot data results.PART.trad <- results.PART.tradition$data results.PART.trad$x <- seq(1,nrow(results.PART.trad), 1) results.PART.trad$x2 <- seq(1,(nrow(results.PART.trad))/2, 1) results.PART.trad$facet <- recode_factor(results.PART.trad$facet, 'Conditional on\nClose = 0' = "Tradition less important", 'Conditional on\nClose = 1' = "Tradition important" ) p.tradition <- ggplot(results.PART.trad) + geom_hline(yintercept = 0, size = 0.5, colour = "black", linetype = "dotted") + geom_pointrange(aes(y = pe, ymin = lower, ymax = upper, x = reorder(var, -x), color=facet, shape=facet), size=0.4, position=position_dodge(width=0.95)) + ylim(-8,5.5) + coord_flip() + facet_grid(~facet) + labs(title="Attending the Landsgemeinde by tradition", y="Change in probability to attend", x="", color="Landsgemeinde as tradition", shape="Landsgemeinde as tradition") + scale_color_brewer(palette="Set1") + theme_minimal() + theme(axis.text.y = element_text(hjust = 0), axis.title.x=element_text(size=11), legend.position="bottom") p.tradition ggsave("fig4_1.eps", dpi=300, units=c("in"), width=8, height=4) ggsave("fig4_1.png", dpi=300, units=c("in"), width=8, height=4.5) ##Friends table(cjLGGL4$Friends) cjLGGL4$Friends_d[cjLGGL4$Friends==1] <- 0 cjLGGL4$Friends_d[cjLGGL4$Friends==2] <- 0 cjLGGL4$Friends_d[cjLGGL4$Friends==3] <- 0 cjLGGL4$Friends_d[cjLGGL4$Friends==4] <- 0 cjLGGL4$Friends_d[cjLGGL4$Friends==5] <- 1 cjLGGL4$Friends_d <- as.factor(cjLGGL4$Friends_d) results.PART.friends.engl <- amce.lmer( formula = particip ~ Agenda:Friends_d + Costs:Friends_d + Outcome:Friends_d + Company:Friends_d + Weather:Friends_d, hierarchy = "(1 | id)", respondent.id = "id", respondent.varying = "Friends_d", baselines = cjLGGLAttr, data = cjLGGL4, na.ignore=T ) summary(results.PART.friends.engl) results.PART.friends.engl$cond.estimates results.PART.friends.engl <- plot(results.PART.friends.engl, main = "Attending the Landsgemeinde", plot.display = "interaction", xlab = "Change in the propensity to participate") #Extract results results.PART.friends <- results.PART.friends.engl$data results.PART.friends$x <- seq(1,nrow(results.PART.friends), 1) results.PART.friends$x2 <- seq(1,(nrow(results.PART.friends))/2, 1) results.PART.friends$facet <- recode_factor(results.PART.friends$facet, 'Conditional on\nClose = 0' = "Meeting friends less important", 'Conditional on\nClose = 1' = "Meeting friends important" ) p.friends <- ggplot(results.PART.friends) + geom_hline(yintercept = 0, size = 0.5, colour = "black", linetype = "dotted") + geom_pointrange(aes(y = pe, ymin = lower, ymax = upper, x = reorder(var, -x), color=facet, shape=facet), size=0.4, position=position_dodge(width=0.95)) + ylim(-11,8) + coord_flip() + facet_grid(~facet) + labs(title="Attending the Landsgemeinde to meet acquiantances", y="Change in probability to attend", x="", color="Important to meet acquiantances", shape="Important to meet acquiantances") + scale_color_brewer(palette="Set1") + theme_minimal() + theme(axis.text.y = element_text(hjust = 0), axis.title.x=element_text(size=11), legend.position="bottom") p.friends ggsave("fig4_2.eps", dpi=300, units=c("in"), width=8, height=4.5) ggsave("fig4_2.png", dpi=300, units=c("in"), width=8, height=4.5) ## Company table(cjLGGL4$Company) results.PART.company.engl <- amce.lmer( formula = particip ~ Company:Agenda + Company:Costs + Company:Outcome + Company:Weather, hierarchy = "(1 | id)", respondent.id = "id", respondent.varying = "Company", baselines = cjLGGLAttr, data = cjLGGL4, na.ignore=T ) summary(results.PART.company.engl) results.PART.company.engl$cond.estimates results.PART.company.engl <- plot(results.PART.company.engl, main = "Attending the Landsgemeinde", xlab = "Change in the propensity to participate", plot.display = "interaction") # save the plot data results.PART.company.d <- results.PART.company.engl$data results.PART.company.d$x <- seq(1,nrow(results.PART.company.d), 1) results.PART.company.d$x2 <- seq(1,(nrow(results.PART.company.d))/5, 1) results.PART.company.d$facet <- recode_factor(results.PART.company.d$facet, 'Conditional on\nCompany = No company' = "No company", 'Conditional on\nCompany = Workmates' = "Workmates", 'Conditional on\nCompany = Family' = "Family", 'Conditional on\nCompany = Neighbours' = "Neighbours", 'Conditional on\nCompany = Friends' = "Friends" ) p.close <- ggplot(results.PART.company.d) + geom_hline(yintercept = 0, size = 0.5, colour = "black", linetype = "dotted") + geom_pointrange(aes(y = pe, ymin = lower, ymax = upper, x = reorder(var, -x), color=facet, shape=facet), size=0.4, position=position_dodge(width=0.95)) + ylim(-8,6) + coord_flip() + facet_grid(~facet) + labs(title="Attending the Landsgemeinde by type of company", y="Change in probability to attend", x="", color="Company", shape="Company") + scale_color_brewer(palette="Set1") + theme_minimal() + theme(axis.text.y = element_text(hjust = 0), axis.title.x=element_text(size=11), legend.position="bottom") p.close ggsave("fig4_3.eps", dpi=300, units=c("in"), width=8, height=4) ggsave("fig4_3.png", dpi=300, units=c("in"), width=8, height=4)