

####
## Replication code for ``Can Rising Powers Reassure?'' by Ryan Powers and Austin Strange
## Conditionally accepted at Journal of Peace Research
###

# load libraries
library(modelsummary)
library(tidyverse)
library(janitor)
library(kableExtra)
library(emmeans) 
library(haven)
library(qwraps2)
library(scales)
library(ggpubr)
library(estimatr)
#plot theme
plot_theme = theme(text = element_text(size=8),  
                   panel.grid.major = element_line(colour = "#EEEEEE", size=.66),
                   panel.grid.major.x = element_blank(),
                   axis.text = element_text(color="black", size=10),
                   axis.line = element_line(colour = "black"),
                   strip.text.y = element_text(angle = 0), axis.title.y = element_text(angle=0, hjust=.5, vjust=.5),
                   axis.title = element_text(lineheight=1.1), 
                   strip.background=element_rect(color=NA, fill="#EEEEEE")) 



#load data 
load("PowersStrange.Rdata")


#### Models 
## we estimate fully-interacted models for each DV and each sample and then generate contrast estimates for each treatment. 
#threats 
#elites
tt_nat_sec_binary_model <- lm_robust(natsec_threat_bin~rhet_treat*behav_treat*country, data = ttngo_data_JPR)
tt_nat_sec_binary_model_means_behav <- emmeans(tt_nat_sec_binary_model, ~ behav_treat, )
tt_nat_sec_binary_model_contrasts_behav <- pairs(infer=TRUE,tt_nat_sec_binary_model_means_behav)  %>% 
  as_tibble() %>%
  mutate(sample = "Elites")
tt_nat_sec_binary_model_means_behav <- tt_nat_sec_binary_model_means_behav %>%
  as_tibble() %>%
  mutate(sample = "Elites") 

#public
dl_nat_sec_binary_model <- lm_robust(natsec_threat_bin~rhet_treat*behav_treat*country, data = dlabss_data_JPR)
dl_nat_sec_binary_model_means_behav <- emmeans(dl_nat_sec_binary_model, ~ behav_treat) 
dl_nat_sec_binary_model_contrasts_behav <- pairs(infer=TRUE,dl_nat_sec_binary_model_means_behav) %>% 
  as_tibble() %>% 
  mutate(sample = "Public")
dl_nat_sec_binary_model_means_behav <- dl_nat_sec_binary_model_means_behav %>% 
  as_tibble() %>% 
  mutate(sample = "Public")

nat_sec_means_behav <- rbind(tt_nat_sec_binary_model_means_behav, dl_nat_sec_binary_model_means_behav) %>% mutate(DV = "Threat to U.S. security")
nat_sec_contrasts_behav <- rbind(tt_nat_sec_binary_model_contrasts_behav, dl_nat_sec_binary_model_contrasts_behav) %>% mutate(DV = "Threat to U.S. security")

#change order
#elites
tt_will_challenge_binary_model <- lm_robust(will_challenge_bin~rhet_treat*behav_treat*country, data = ttngo_data_JPR)
tt_will_challenge_binary_model_means_behav <- emmeans(tt_will_challenge_binary_model, ~ behav_treat)
tt_will_challenge_binary_model_contrasts_behav <- pairs(infer=TRUE,tt_will_challenge_binary_model_means_behav)  %>% 
  as_tibble() %>%
  mutate(sample = "Elites")
tt_will_challenge_binary_model_means_behav <- tt_will_challenge_binary_model_means_behav %>%
  as_tibble() %>%
  mutate(sample = "Elites") 

#public
dl_will_challenge_binary_model <- lm_robust(will_challenge_bin~rhet_treat*behav_treat*country, data = dlabss_data_JPR)
dl_will_challenge_binary_model_means_behav <- emmeans(dl_will_challenge_binary_model, ~ behav_treat) 
dl_will_challenge_binary_model_contrasts_behav <- pairs(infer=TRUE,dl_will_challenge_binary_model_means_behav) %>% 
  as_tibble() %>% 
  mutate(sample = "Public")
dl_will_challenge_binary_model_means_behav <- dl_will_challenge_binary_model_means_behav %>% 
  as_tibble() %>% 
  mutate(sample = "Public")

will_challenge_means_behav <- rbind(tt_will_challenge_binary_model_means_behav, dl_will_challenge_binary_model_means_behav) %>% mutate(DV = "Revise int'l order")
will_challenge_contrasts_behav <- rbind(tt_will_challenge_binary_model_contrasts_behav, dl_will_challenge_binary_model_contrasts_behav) %>% mutate(DV = "Revise int'l order")

#fp influence
#elites
tt_elite_influence_binary_model <- lm_robust(elite_influence_bin~rhet_treat*behav_treat*country, data = ttngo_data_JPR)
tt_elite_influence_binary_model_means_behav <- emmeans(tt_elite_influence_binary_model, ~ behav_treat)
tt_elite_influence_binary_model_contrasts_behav <- pairs(infer=TRUE,tt_elite_influence_binary_model_means_behav)  %>% 
  as_tibble() %>%
  mutate(sample = "Elites")
tt_elite_influence_binary_model_means_behav <- tt_elite_influence_binary_model_means_behav %>%
  as_tibble() %>%
  mutate(sample = "Elites") 

#public
dl_elite_influence_binary_model <- lm_robust(elite_influence_bin~rhet_treat*behav_treat*country, data = ttngo_data_JPR)
dl_elite_influence_binary_model_means_behav <- emmeans(dl_elite_influence_binary_model, ~ behav_treat) 
dl_elite_influence_binary_model_contrasts_behav <- pairs(infer=TRUE,dl_elite_influence_binary_model_means_behav) %>% 
  as_tibble() %>% 
  mutate(sample = "Public")
dl_elite_influence_binary_model_means_behav <- dl_elite_influence_binary_model_means_behav %>% 
  as_tibble() %>% 
  mutate(sample = "Public")

elite_influence_means_behav <- rbind(tt_elite_influence_binary_model_means_behav, dl_elite_influence_binary_model_means_behav) %>% mutate(DV = "Influence recipient FP")
elite_influence_contrasts_behav <- rbind(tt_elite_influence_binary_model_contrasts_behav, dl_elite_influence_binary_model_contrasts_behav) %>% mutate(DV = "Influence recipient FP")

#should have more influence
#elites
tt_should_more_influence_binary_model <- lm_robust(should_more_influence_bin~rhet_treat*behav_treat*country, data = ttngo_data_JPR)
tt_should_more_influence_binary_model_means_behav <- emmeans(tt_should_more_influence_binary_model, ~ behav_treat)
tt_should_more_influence_binary_model_contrasts_behav <- pairs(infer=TRUE,tt_should_more_influence_binary_model_means_behav)  %>% 
  as_tibble() %>%
  mutate(sample = "Elites")
tt_should_more_influence_binary_model_means_behav <- tt_should_more_influence_binary_model_means_behav %>%
  as_tibble() %>%
  mutate(sample = "Elites") 

#public
dl_should_more_influence_binary_model <- lm_robust(should_more_influence_bin~rhet_treat*behav_treat*country, data = dlabss_data_JPR)
dl_should_more_influence_binary_model_means_behav <- emmeans(dl_should_more_influence_binary_model, ~ behav_treat) 
dl_should_more_influence_binary_model_contrasts_behav <- pairs(infer=TRUE,dl_should_more_influence_binary_model_means_behav) %>% 
  as_tibble() %>% 
  mutate(sample = "Public")
dl_should_more_influence_binary_model_means_behav <- dl_should_more_influence_binary_model_means_behav %>% 
  as_tibble() %>% 
  mutate(sample = "Public")

more_influence_means_behav <- rbind(tt_should_more_influence_binary_model_means_behav, dl_should_more_influence_binary_model_means_behav) %>% mutate(DV = "Should have more influence")
more_influence_contrasts_behav <- rbind(tt_should_more_influence_binary_model_contrasts_behav, dl_should_more_influence_binary_model_contrasts_behav) %>% mutate(DV = "Should have more influence")

#elite only 
#public in recipient countries 
tt_popular_influence_binary_model <- lm_robust(popular_influence_bin~rhet_treat*behav_treat*country, data = ttngo_data_JPR)
tt_popular_influence_binary_model_means_behav <- emmeans(tt_popular_influence_binary_model, ~ behav_treat)
tt_popular_influence_binary_model_contrasts_behav <- pairs(infer=TRUE,tt_popular_influence_binary_model_means_behav)  %>% 
  as_tibble() %>%
  mutate(sample = "Elites", DV = "Public influence")
tt_popular_influence_binary_model_means_behav <- tt_popular_influence_binary_model_means_behav %>%
  as_tibble() %>%
  mutate(sample = "Elites", DV = "Public influence") 

#public only
#responsible stakeholder
dl_responsible_stakeholder_binary_model <- lm_robust(responsible_stakeholder_bin~rhet_treat*behav_treat*country, data = dlabss_data_JPR)
dl_responsible_stakeholder_binary_model_means_behav <- emmeans(dl_responsible_stakeholder_binary_model, ~ behav_treat) 
dl_responsible_stakeholder_binary_model_contrasts_behav <- pairs(infer=TRUE,dl_responsible_stakeholder_binary_model_means_behav) %>% 
  as_tibble() %>% 
  mutate(sample = "Public", DV = "Responsible stakeholder")
dl_responsible_stakeholder_binary_model_means_behav <- dl_responsible_stakeholder_binary_model_means_behav %>% 
  as_tibble() %>% 
  mutate(sample = "Public", DV = "Responsible stakeholder")

#threaten us influence
dl_threaten_us_influence_binary_model <- lm_robust(threaten_us_influence_bin~rhet_treat*behav_treat*country, data = dlabss_data_JPR)
dl_threaten_us_influence_binary_model_means_behav <- emmeans(dl_threaten_us_influence_binary_model, ~ behav_treat) 
dl_threaten_us_influence_binary_model_contrasts_behav <- pairs(infer=TRUE,dl_threaten_us_influence_binary_model_means_behav) %>% 
  as_tibble() %>% 
  mutate(sample = "Public", DV = "Threaten US influence")
dl_threaten_us_influence_binary_model_means_behav <- dl_threaten_us_influence_binary_model_means_behav %>% 
  as_tibble() %>% 
  mutate(sample = "Public", DV = "Threaten US influence")



combined_means_behav <- rbind(nat_sec_means_behav, will_challenge_means_behav, elite_influence_means_behav, more_influence_means_behav, tt_popular_influence_binary_model_means_behav ) 
combined_contrasts_behav <- rbind(nat_sec_contrasts_behav, will_challenge_contrasts_behav, elite_influence_contrasts_behav, more_influence_contrasts_behav, tt_popular_influence_binary_model_contrasts_behav)

combined_contrasts_for_text_behav <- combined_contrasts_behav %>% 
  mutate(estimate = round(estimate, 1), lower.CL = round(lower.CL, 1),  upper.CL = round(upper.CL, 1), p.value = format.pval(pv=p.value, digits=3, eps = 0.001,  nsmall = 3)) %>%
  arrange(sample)
combined_contrasts_for_text_behav

combined_means_for_text_behav <- combined_means_behav %>% 
  filter(DV == "Threat to U.S. security" | DV == "Revise int'l order" | DV == "Should have more influence") %>%
  mutate(emmean = round(emmean, 1), lower.CL = round(lower.CL, 1),  upper.CL = round(upper.CL, 1)) %>%
  arrange(sample)
combined_means_for_text_behav



#### rhet_treat_contrasts

#threats 
#elites
tt_nat_sec_binary_model_means_rhet <- emmeans(tt_nat_sec_binary_model, ~ rhet_treat)
tt_nat_sec_binary_model_contrasts_rhet <- pairs(infer=TRUE,tt_nat_sec_binary_model_means_rhet)  %>% 
  as_tibble() %>%
  mutate(sample = "Elites")
tt_nat_sec_binary_model_means_rhet <- tt_nat_sec_binary_model_means_rhet %>%
  as_tibble() %>%
  mutate(sample = "Elites") 

#public
dl_nat_sec_binary_model_means_rhet <- emmeans(dl_nat_sec_binary_model, ~ rhet_treat) 
dl_nat_sec_binary_model_contrasts_rhet <- pairs(infer=TRUE,dl_nat_sec_binary_model_means_rhet) %>% 
  as_tibble() %>% 
  mutate(sample = "Public")
dl_nat_sec_binary_model_means_rhet <- dl_nat_sec_binary_model_means_rhet %>% 
  as_tibble() %>% 
  mutate(sample = "Public")

nat_sec_means_rhet <- rbind(tt_nat_sec_binary_model_means_rhet, dl_nat_sec_binary_model_means_rhet) %>% mutate(DV = "Threat to U.S. security")
nat_sec_contrasts_rhet <- rbind(tt_nat_sec_binary_model_contrasts_rhet, dl_nat_sec_binary_model_contrasts_rhet) %>% mutate(DV = "Threat to U.S. security")

#change order
#elites
tt_will_challenge_binary_model_means_rhet <- emmeans(tt_will_challenge_binary_model, ~ rhet_treat)
tt_will_challenge_binary_model_contrasts_rhet <- pairs(infer=TRUE,tt_will_challenge_binary_model_means_rhet)  %>% 
  as_tibble() %>%
  mutate(sample = "Elites")
tt_will_challenge_binary_model_means_rhet <- tt_will_challenge_binary_model_means_rhet %>%
  as_tibble() %>%
  mutate(sample = "Elites") 

#public
dl_will_challenge_binary_model_means_rhet <- emmeans(dl_will_challenge_binary_model, ~ rhet_treat) 
dl_will_challenge_binary_model_contrasts_rhet <- pairs(infer=TRUE,dl_will_challenge_binary_model_means_rhet) %>% 
  as_tibble() %>% 
  mutate(sample = "Public")
dl_will_challenge_binary_model_means_rhet <- dl_will_challenge_binary_model_means_rhet %>% 
  as_tibble() %>% 
  mutate(sample = "Public")

will_challenge_means_rhet <- rbind(tt_will_challenge_binary_model_means_rhet, dl_will_challenge_binary_model_means_rhet) %>% mutate(DV = "Revise int'l order")
will_challenge_contrasts_rhet <- rbind(tt_will_challenge_binary_model_contrasts_rhet, dl_will_challenge_binary_model_contrasts_rhet) %>% mutate(DV = "Revise int'l order")



#fp influence
#elites
tt_elite_influence_binary_model_means_rhet <- emmeans(tt_elite_influence_binary_model, ~ rhet_treat)
tt_elite_influence_binary_model_contrasts_rhet <- pairs(infer=TRUE,tt_elite_influence_binary_model_means_rhet)  %>% 
  as_tibble() %>%
  mutate(sample = "Elites")
tt_elite_influence_binary_model_means_rhet <- tt_elite_influence_binary_model_means_rhet %>%
  as_tibble() %>%
  mutate(sample = "Elites") 

#public
dl_elite_influence_binary_model_means_rhet <- emmeans(dl_elite_influence_binary_model, ~ rhet_treat) 
dl_elite_influence_binary_model_contrasts_rhet <- pairs(infer=TRUE,dl_elite_influence_binary_model_means_rhet) %>% 
  as_tibble() %>% 
  mutate(sample = "Public")
dl_elite_influence_binary_model_means_rhet <- dl_elite_influence_binary_model_means_rhet %>% 
  as_tibble() %>% 
  mutate(sample = "Public")

elite_influence_means_rhet <- rbind(tt_elite_influence_binary_model_means_rhet, dl_elite_influence_binary_model_means_rhet) %>% mutate(DV = "Influence recipient FP")
elite_influence_contrasts_rhet <- rbind(tt_elite_influence_binary_model_contrasts_rhet, dl_elite_influence_binary_model_contrasts_rhet) %>% mutate(DV = "Influence recipient FP")



#should have more influence
#elites
tt_should_more_influence_binary_model_means_rhet <- emmeans(tt_should_more_influence_binary_model, ~ rhet_treat)
tt_should_more_influence_binary_model_contrasts_rhet <- pairs(infer=TRUE,tt_should_more_influence_binary_model_means_rhet)  %>% 
  as_tibble() %>%
  mutate(sample = "Elites")
tt_should_more_influence_binary_model_means_rhet <- tt_should_more_influence_binary_model_means_rhet %>%
  as_tibble() %>%
  mutate(sample = "Elites") 

#public
dl_should_more_influence_binary_model_means_rhet <- emmeans(dl_should_more_influence_binary_model, ~ rhet_treat) 
dl_should_more_influence_binary_model_contrasts_rhet <- pairs(infer=TRUE,dl_should_more_influence_binary_model_means_rhet) %>% 
  as_tibble() %>% 
  mutate(sample = "Public")
dl_should_more_influence_binary_model_means_rhet <- dl_should_more_influence_binary_model_means_rhet %>% 
  as_tibble() %>% 
  mutate(sample = "Public")

more_influence_means_rhet <- rbind(tt_should_more_influence_binary_model_means_rhet, dl_should_more_influence_binary_model_means_rhet) %>% mutate(DV = "Should have more influence")
more_influence_contrasts_rhet <- rbind(tt_should_more_influence_binary_model_contrasts_rhet, dl_should_more_influence_binary_model_contrasts_rhet) %>% mutate(DV = "Should have more influence")


#elite only 
#public in recipient countries 
tt_popular_influence_binary_model_means_rhet <- emmeans(tt_popular_influence_binary_model, ~ rhet_treat)
tt_popular_influence_binary_model_contrasts_rhet <- pairs(infer=TRUE,tt_popular_influence_binary_model_means_rhet)  %>% 
  as_tibble() %>%
  mutate(sample = "Elites", DV = "Public influence")
tt_popular_influence_binary_model_means_rhet <- tt_popular_influence_binary_model_means_rhet %>%
  as_tibble() %>%
  mutate(sample = "Elites", DV = "Public influence") 


#public only
#responsible stakeholder
dl_responsible_stakeholder_binary_model_means_rhet <- emmeans(dl_responsible_stakeholder_binary_model, ~ rhet_treat) 
dl_responsible_stakeholder_binary_model_contrasts_rhet <- pairs(infer=TRUE,dl_responsible_stakeholder_binary_model_means_rhet) %>% 
  as_tibble() %>% 
  mutate(sample = "Public", DV = "Responsible stakeholder")
dl_responsible_stakeholder_binary_model_means_rhet <- dl_responsible_stakeholder_binary_model_means_rhet %>% 
  as_tibble() %>% 
  mutate(sample = "Public", DV = "Responsible stakeholder")


#threaten us influence
dl_threaten_us_influence_binary_model_means_rhet <- emmeans(dl_threaten_us_influence_binary_model, ~ rhet_treat) 
dl_threaten_us_influence_binary_model_contrasts_rhet <- pairs(infer=TRUE,dl_threaten_us_influence_binary_model_means_rhet) %>% 
  as_tibble() %>% 
  mutate(sample = "Public", DV = "Threaten US influence")
dl_threaten_us_influence_binary_model_means_rhet <- dl_threaten_us_influence_binary_model_means_rhet %>% 
  as_tibble() %>% 
  mutate(sample = "Public", DV = "Threaten US influence")




combined_means_rhet <- rbind(nat_sec_means_rhet, will_challenge_means_rhet, elite_influence_means_rhet, more_influence_means_rhet)
combined_contrasts_rhet <- rbind(nat_sec_contrasts_rhet, will_challenge_contrasts_rhet, elite_influence_contrasts_rhet, more_influence_contrasts_rhet)

combined_contrasts_for_text_rhet <- combined_contrasts_rhet %>% 
  mutate(estimate = round(estimate, 1), lower.CL = round(lower.CL, 1),  upper.CL = round(upper.CL, 1), p.value = format.pval(pv=p.value, digits=3, eps = 0.001,  nsmall = 3)) %>%
  arrange(sample)
combined_contrasts_for_text_rhet

combined_means_for_text_rhet <- combined_means_rhet %>% 
  #filter(DV == "Threat to U.S. security" | DV == "Revise int'l order") %>%
  mutate(emmean = round(emmean, 1), lower.CL = round(lower.CL, 1),  upper.CL = round(upper.CL, 1)) %>%
  arrange(sample)
combined_means_for_text_rhet






#### rhet_treat_behavior_interactions

#threats 
#elites
tt_nat_sec_binary_model_means_rhet_behav_inter<- emmeans(tt_nat_sec_binary_model, ~ rhet_treat*behav_treat)
tt_nat_sec_binary_model_contrasts_rhet_behav_inter<- contrast(infer=TRUE,tt_nat_sec_binary_model_means_rhet_behav_inter, interaction = c(rhet_treat = "pairwise"), by = "behav_treat") %>% 
  as_tibble() %>%
  mutate(sample = "Elites")
tt_nat_sec_binary_model_contrasts_rhet_behav_wbase<- contrast(infer=TRUE,tt_nat_sec_binary_model_means_rhet_behav_inter, "trt.vs.ctrl", combine = TRUE) %>% 
  as_tibble() %>%
  mutate(sample = "Elites")
tt_nat_sec_binary_model_means_rhet_behav_inter<- tt_nat_sec_binary_model_means_rhet_behav_inter%>%
  as_tibble() %>%
  mutate(sample = "Elites") 

#public
dl_nat_sec_binary_model_means_rhet_behav_inter<- emmeans(dl_nat_sec_binary_model, ~ rhet_treat*behav_treat) 
dl_nat_sec_binary_model_contrasts_rhet_behav_inter<- contrast(infer=TRUE,dl_nat_sec_binary_model_means_rhet_behav_inter, interaction = c(rhet_treat = "pairwise"), by = "behav_treat") %>% 
  as_tibble() %>% 
  mutate(sample = "Public")
dl_nat_sec_binary_model_contrasts_rhet_behav_wbase<- contrast(infer=TRUE,dl_nat_sec_binary_model_means_rhet_behav_inter,  "trt.vs.ctrl", combine = TRUE) %>% 
  as_tibble() %>% 
  mutate(sample = "Public")
dl_nat_sec_binary_model_means_rhet_behav_inter<- dl_nat_sec_binary_model_means_rhet_behav_inter%>% 
  as_tibble() %>% 
  mutate(sample = "Public")

nat_sec_means_rhet_behav_inter<- rbind(tt_nat_sec_binary_model_means_rhet_behav_inter, dl_nat_sec_binary_model_means_rhet_behav_inter) %>% mutate(DV = "Threat to U.S. security")
nat_sec_contrasts_rhet_behav_wbase<- rbind(tt_nat_sec_binary_model_contrasts_rhet_behav_wbase, dl_nat_sec_binary_model_contrasts_rhet_behav_wbase) %>% mutate(DV = "Threat to U.S. security")
nat_sec_contrasts_rhet_behav_inter<- rbind(tt_nat_sec_binary_model_contrasts_rhet_behav_inter, dl_nat_sec_binary_model_contrasts_rhet_behav_inter) %>% mutate(DV = "Threat to U.S. security")

#change order
#elites
tt_will_challenge_binary_model_means_rhet_behav_inter<- emmeans(tt_will_challenge_binary_model, ~ rhet_treat*behav_treat)
tt_will_challenge_binary_model_contrasts_rhet_behav_inter<- contrast(infer=TRUE,tt_will_challenge_binary_model_means_rhet_behav_inter, interaction = c(rhet_treat = "pairwise"), by = "behav_treat")  %>% 
  as_tibble() %>%
  mutate(sample = "Elites")
tt_will_challenge_binary_model_contrasts_rhet_behav_wbase<- contrast(infer=TRUE,tt_will_challenge_binary_model_means_rhet_behav_inter, "trt.vs.ctrl", combine = TRUE)  %>% 
  as_tibble() %>%
  mutate(sample = "Elites")
tt_will_challenge_binary_model_means_rhet_behav_inter<- tt_will_challenge_binary_model_means_rhet_behav_inter%>%
  as_tibble() %>%
  mutate(sample = "Elites") 

#public
dl_will_challenge_binary_model_means_rhet_behav_inter<- emmeans(dl_will_challenge_binary_model, ~ rhet_treat*behav_treat) 
dl_will_challenge_binary_model_contrasts_rhet_behav_inter<- contrast(infer=TRUE,dl_will_challenge_binary_model_means_rhet_behav_inter, interaction = c(rhet_treat = "pairwise"), by = "behav_treat")%>% 
  as_tibble() %>% 
  mutate(sample = "Public")
dl_will_challenge_binary_model_contrasts_rhet_behav_wbase<- contrast(infer=TRUE,dl_will_challenge_binary_model_means_rhet_behav_inter,  "trt.vs.ctrl", combine = TRUE)%>% 
  as_tibble() %>% 
  mutate(sample = "Public")
dl_will_challenge_binary_model_means_rhet_behav_inter<- dl_will_challenge_binary_model_means_rhet_behav_inter%>% 
  as_tibble() %>% 
  mutate(sample = "Public")

will_challenge_means_rhet_behav_inter<- rbind(tt_will_challenge_binary_model_means_rhet_behav_inter, dl_will_challenge_binary_model_means_rhet_behav_inter) %>% mutate(DV = "Revise int'l order")
will_challenge_contrasts_rhet_behav_inter<- rbind(tt_will_challenge_binary_model_contrasts_rhet_behav_inter, dl_will_challenge_binary_model_contrasts_rhet_behav_inter) %>% mutate(DV = "Revise int'l order")
will_challenge_contrasts_rhet_behav_wbase<- rbind(tt_will_challenge_binary_model_contrasts_rhet_behav_wbase, dl_will_challenge_binary_model_contrasts_rhet_behav_wbase) %>% mutate(DV = "Revise int'l order")



#fp influence
#elites
tt_elite_influence_binary_model_means_rhet_behav_inter<- emmeans(tt_elite_influence_binary_model, ~ rhet_treat*behav_treat)
tt_elite_influence_binary_model_contrasts_rhet_behav_inter<- contrast(infer=TRUE,tt_elite_influence_binary_model_means_rhet_behav_inter, interaction = c(rhet_treat = "pairwise"), by = "behav_treat")  %>% 
  as_tibble() %>%
  mutate(sample = "Elites")
tt_elite_influence_binary_model_contrasts_rhet_behav_wbase<- contrast(infer=TRUE,tt_elite_influence_binary_model_means_rhet_behav_inter, "trt.vs.ctrl", combine = TRUE)  %>% 
  as_tibble() %>%
  mutate(sample = "Elites")
tt_elite_influence_binary_model_means_rhet_behav_inter<- tt_elite_influence_binary_model_means_rhet_behav_inter%>%
  as_tibble() %>%
  mutate(sample = "Elites") 

#public
dl_elite_influence_binary_model_means_rhet_behav_inter<- emmeans(dl_elite_influence_binary_model, ~ rhet_treat*behav_treat) 
dl_elite_influence_binary_model_contrasts_rhet_behav_inter<- contrast(infer=TRUE,dl_elite_influence_binary_model_means_rhet_behav_inter, interaction = c(rhet_treat = "pairwise"), by = "behav_treat") %>% 
  as_tibble() %>% 
  mutate(sample = "Public")
dl_elite_influence_binary_model_contrasts_rhet_behav_wbase<- contrast(infer=TRUE,dl_elite_influence_binary_model_means_rhet_behav_inter, "trt.vs.ctrl", combine = TRUE) %>% 
  as_tibble() %>% 
  mutate(sample = "Public")
dl_elite_influence_binary_model_means_rhet_behav_inter<- dl_elite_influence_binary_model_means_rhet_behav_inter%>% 
  as_tibble() %>% 
  mutate(sample = "Public")

elite_influence_means_rhet_behav_inter<- rbind(tt_elite_influence_binary_model_means_rhet_behav_inter, dl_elite_influence_binary_model_means_rhet_behav_inter) %>% mutate(DV = "Influence recipient FP")
elite_influence_contrasts_rhet_behav_inter<- rbind(tt_elite_influence_binary_model_contrasts_rhet_behav_inter, dl_elite_influence_binary_model_contrasts_rhet_behav_inter) %>% mutate(DV = "Influence recipient FP")
elite_influence_contrasts_rhet_behav_wbase<- rbind(tt_elite_influence_binary_model_contrasts_rhet_behav_wbase, dl_elite_influence_binary_model_contrasts_rhet_behav_wbase) %>% mutate(DV = "Influence recipient FP")



#should have more influence
#elites
tt_should_more_influence_binary_model_means_rhet_behav_inter<- emmeans(tt_should_more_influence_binary_model, ~ rhet_treat*behav_treat)
tt_should_more_influence_binary_model_contrasts_rhet_behav_inter<- contrast(infer=TRUE,tt_should_more_influence_binary_model_means_rhet_behav_inter, interaction = c(rhet_treat = "pairwise"), by = "behav_treat")  %>% 
  as_tibble() %>%
  mutate(sample = "Elites")
tt_should_more_influence_binary_model_contrasts_rhet_behav_wbase<- contrast(infer=TRUE,tt_should_more_influence_binary_model_means_rhet_behav_inter, "trt.vs.ctrl", combine = TRUE)  %>% 
  as_tibble() %>%
  mutate(sample = "Elites")
tt_should_more_influence_binary_model_means_rhet_behav_inter<- tt_should_more_influence_binary_model_means_rhet_behav_inter%>%
  as_tibble() %>%
  mutate(sample = "Elites") 

#public
dl_should_more_influence_binary_model_means_rhet_behav_inter<- emmeans(dl_should_more_influence_binary_model, ~ rhet_treat*behav_treat) 
dl_should_more_influence_binary_model_contrasts_rhet_behav_inter<- contrast(infer=TRUE,dl_should_more_influence_binary_model_means_rhet_behav_inter, interaction = c(rhet_treat = "pairwise"), by = "behav_treat") %>% 
  as_tibble() %>% 
  mutate(sample = "Public")
dl_should_more_influence_binary_model_contrasts_rhet_behav_wbase<- contrast(infer=TRUE,dl_should_more_influence_binary_model_means_rhet_behav_inter, "trt.vs.ctrl", combine = TRUE) %>% 
  as_tibble() %>% 
  mutate(sample = "Public")
dl_should_more_influence_binary_model_means_rhet_behav_inter<- dl_should_more_influence_binary_model_means_rhet_behav_inter%>% 
  as_tibble() %>% 
  mutate(sample = "Public")

more_influence_means_rhet_behav_inter<- rbind(tt_should_more_influence_binary_model_means_rhet_behav_inter, dl_should_more_influence_binary_model_means_rhet_behav_inter) %>% mutate(DV = "Should have more influence")
more_influence_contrasts_rhet_behav_inter<- rbind(tt_should_more_influence_binary_model_contrasts_rhet_behav_inter, dl_should_more_influence_binary_model_contrasts_rhet_behav_inter) %>% mutate(DV = "Should have more influence")
more_influence_contrasts_rhet_behav_wbase<- rbind(tt_should_more_influence_binary_model_contrasts_rhet_behav_wbase, dl_should_more_influence_binary_model_contrasts_rhet_behav_wbase) %>% mutate(DV = "Should have more influence")


#elite only 
#public in recipient countries 
tt_popular_influence_binary_model_means_rhet_behav_inter<- emmeans(tt_popular_influence_binary_model, ~ rhet_treat*behav_treat)
tt_popular_influence_binary_model_contrasts_rhet_behav_inter<- contrast(infer=TRUE,tt_popular_influence_binary_model_means_rhet_behav_inter, interaction = c(rhet_treat = "pairwise"), by = "behav_treat")  %>% 
  as_tibble() %>%
  mutate(sample = "Elites", DV = "Public influence")
tt_popular_influence_binary_model_contrasts_rhet_behav_wbase<- contrast(infer=TRUE,tt_popular_influence_binary_model_means_rhet_behav_inter, "trt.vs.ctrl", combine = TRUE)  %>% 
  as_tibble() %>%
  mutate(sample = "Elites", DV = "Public influence")
tt_popular_influence_binary_model_means_rhet_behav_inter<- tt_popular_influence_binary_model_means_rhet_behav_inter%>%
  as_tibble() %>%
  mutate(sample = "Elites", DV = "Public influence") 


#public only
#responsible stakeholder
dl_responsible_stakeholder_binary_model_means_rhet_behav_inter<- emmeans(dl_responsible_stakeholder_binary_model, ~ rhet_treat*behav_treat) 
dl_responsible_stakeholder_binary_model_contrasts_rhet_behav_inter<- contrast(infer=TRUE,dl_responsible_stakeholder_binary_model_means_rhet_behav_inter, interaction = c(rhet_treat = "pairwise"), by = "behav_treat") %>% 
  as_tibble() %>% 
  mutate(sample = "Public", DV = "Responsible stakeholder")
dl_responsible_stakeholder_binary_model_contrasts_rhet_behav_wbase<- contrast(infer=TRUE,dl_responsible_stakeholder_binary_model_means_rhet_behav_inter,  "trt.vs.ctrl", combine = TRUE) %>% 
  as_tibble() %>% 
  mutate(sample = "Public", DV = "Responsible stakeholder")
dl_responsible_stakeholder_binary_model_means_rhet_behav_inter<- dl_responsible_stakeholder_binary_model_means_rhet_behav_inter%>% 
  as_tibble() %>% 
  mutate(sample = "Public", DV = "Responsible stakeholder")


#threaten us influence
dl_threaten_us_influence_binary_model_means_rhet_behav_inter<- emmeans(dl_threaten_us_influence_binary_model, ~ rhet_treat*behav_treat) 
dl_threaten_us_influence_binary_model_contrasts_rhet_behav_inter<- contrast(infer=TRUE,dl_threaten_us_influence_binary_model_means_rhet_behav_inter, interaction = c(rhet_treat = "pairwise"), by = "behav_treat") %>% 
  as_tibble() %>% 
  mutate(sample = "Public", DV = "Threaten US influence")
dl_threaten_us_influence_binary_model_contrasts_rhet_behav_wbase<- contrast(infer=TRUE,dl_threaten_us_influence_binary_model_means_rhet_behav_inter,"trt.vs.ctrl", combine = TRUE) %>% 
  as_tibble() %>% 
  mutate(sample = "Public", DV = "Threaten US influence")
dl_threaten_us_influence_binary_model_means_rhet_behav_inter<- dl_threaten_us_influence_binary_model_means_rhet_behav_inter%>% 
  as_tibble() %>% 
  mutate(sample = "Public", DV = "Threaten US influence")



combined_means_rhet_behav_inter<- rbind(nat_sec_means_rhet_behav_inter, will_challenge_means_rhet_behav_inter, elite_influence_means_rhet_behav_inter, more_influence_means_rhet_behav_inter)
combined_contrasts_rhet_behav_inter<- rbind(nat_sec_contrasts_rhet_behav_inter, will_challenge_contrasts_rhet_behav_inter, elite_influence_contrasts_rhet_behav_inter, more_influence_contrasts_rhet_behav_inter)
combined_contrasts_rhet_behav_wbase<- rbind(nat_sec_contrasts_rhet_behav_wbase, will_challenge_contrasts_rhet_behav_wbase, elite_influence_contrasts_rhet_behav_wbase, more_influence_contrasts_rhet_behav_wbase)


combined_contrasts_for_text_rhet_behav_inter<- combined_contrasts_rhet_behav_inter%>% 
  mutate(estimate = round(estimate, 1), lower.CL = round(lower.CL, 1),  upper.CL = round(upper.CL, 1), p.value = format.pval(pv=p.value, digits=3, eps = 0.001,  nsmall = 3)) %>%
  arrange(sample)
combined_contrasts_for_text_rhet_behav_inter


combined_contrasts_for_text_rhet_behav_wbase<- combined_contrasts_rhet_behav_wbase%>% 
  mutate(estimate = round(estimate, 1), lower.CL = round(lower.CL, 1),  upper.CL = round(upper.CL, 1), p.value = format.pval(pv=p.value, digits=3, eps = 0.001,  nsmall = 3)) %>%
  arrange(sample) %>%
  mutate(contrast_label = case_when( contrast == "Status Quo Bad Aid - Revisionist Bad Aid" ~ "2) SQ Rhetoric & Rev. Behavior",
                                     contrast == "Revisionist Good Aid - Revisionist Bad Aid" ~ "3) Rev. Rhetoric & SQ Behavior",
                                     contrast == "Status Quo Good Aid - Revisionist Bad Aid" ~ "4) SQ Rhetoric & SQ Behavior"))
combined_contrasts_for_text_rhet_behav_wbase


combined_means_for_text_rhet_behav_inter<- combined_means_rhet_behav_inter%>% 
  mutate(emmean = round(emmean, 1), lower.CL = round(lower.CL, 1),  upper.CL = round(upper.CL, 1)) %>%
  arrange(sample)
combined_means_for_text_rhet_behav_inter


combined_means_for_text_rhet_behav_inter %>% filter(DV == "Threat to U.S. security")




#### Pull out substantive effects for treatment interactions 

#threats 
#elites
tt_nat_sec_binary_model_means_rhet_behav_inter<- emmeans(tt_nat_sec_binary_model, ~ rhet_treat*behav_treat)
tt_nat_sec_binary_model_contrasts_rhet_behav_inter<- contrast(infer=TRUE,tt_nat_sec_binary_model_means_rhet_behav_inter, interaction = c(rhet_treat = "pairwise"), by = "behav_treat") %>% 
  as_tibble() %>%
  mutate(sample = "Elites")
tt_nat_sec_binary_model_contrasts_rhet_behav_wbase<- contrast(infer=TRUE,tt_nat_sec_binary_model_means_rhet_behav_inter, "trt.vs.ctrl", combine = TRUE) %>% 
  as_tibble() %>%
  mutate(sample = "Elites")
tt_nat_sec_binary_model_means_rhet_behav_inter<- tt_nat_sec_binary_model_means_rhet_behav_inter%>%
  as_tibble() %>%
  mutate(sample = "Elites") 

#public
dl_nat_sec_binary_model_means_rhet_behav_inter<- emmeans(dl_nat_sec_binary_model, ~ rhet_treat*behav_treat) 
dl_nat_sec_binary_model_contrasts_rhet_behav_inter<- contrast(infer=TRUE,dl_nat_sec_binary_model_means_rhet_behav_inter, interaction = c(rhet_treat = "pairwise"), by = "behav_treat") %>% 
  as_tibble() %>% 
  mutate(sample = "Public")
dl_nat_sec_binary_model_contrasts_rhet_behav_wbase<- contrast(infer=TRUE,dl_nat_sec_binary_model_means_rhet_behav_inter,  "trt.vs.ctrl", combine = TRUE) %>% 
  as_tibble() %>% 
  mutate(sample = "Public")
dl_nat_sec_binary_model_means_rhet_behav_inter<- dl_nat_sec_binary_model_means_rhet_behav_inter%>% 
  as_tibble() %>% 
  mutate(sample = "Public")

nat_sec_means_rhet_behav_inter<- rbind(tt_nat_sec_binary_model_means_rhet_behav_inter, dl_nat_sec_binary_model_means_rhet_behav_inter) %>% mutate(DV = "Threat to U.S. security")
nat_sec_contrasts_rhet_behav_wbase<- rbind(tt_nat_sec_binary_model_contrasts_rhet_behav_wbase, dl_nat_sec_binary_model_contrasts_rhet_behav_wbase) %>% mutate(DV = "Threat to U.S. security")
nat_sec_contrasts_rhet_behav_inter<- rbind(tt_nat_sec_binary_model_contrasts_rhet_behav_inter, dl_nat_sec_binary_model_contrasts_rhet_behav_inter) %>% mutate(DV = "Threat to U.S. security")

#change order
#elites
tt_will_challenge_binary_model_means_rhet_behav_inter<- emmeans(tt_will_challenge_binary_model, ~ rhet_treat*behav_treat)
tt_will_challenge_binary_model_contrasts_rhet_behav_inter<- contrast(infer=TRUE,tt_will_challenge_binary_model_means_rhet_behav_inter, interaction = c(rhet_treat = "pairwise"), by = "behav_treat")  %>% 
  as_tibble() %>%
  mutate(sample = "Elites")
tt_will_challenge_binary_model_contrasts_rhet_behav_wbase<- contrast(infer=TRUE,tt_will_challenge_binary_model_means_rhet_behav_inter, "trt.vs.ctrl", combine = TRUE)  %>% 
  as_tibble() %>%
  mutate(sample = "Elites")
tt_will_challenge_binary_model_means_rhet_behav_inter<- tt_will_challenge_binary_model_means_rhet_behav_inter%>%
  as_tibble() %>%
  mutate(sample = "Elites") 

#public
dl_will_challenge_binary_model_means_rhet_behav_inter<- emmeans(dl_will_challenge_binary_model, ~ rhet_treat*behav_treat) 
dl_will_challenge_binary_model_contrasts_rhet_behav_inter<- contrast(infer=TRUE,dl_will_challenge_binary_model_means_rhet_behav_inter, interaction = c(rhet_treat = "pairwise"), by = "behav_treat")%>% 
  as_tibble() %>% 
  mutate(sample = "Public")
dl_will_challenge_binary_model_contrasts_rhet_behav_wbase<- contrast(infer=TRUE,dl_will_challenge_binary_model_means_rhet_behav_inter,  "trt.vs.ctrl", combine = TRUE)%>% 
  as_tibble() %>% 
  mutate(sample = "Public")
dl_will_challenge_binary_model_means_rhet_behav_inter<- dl_will_challenge_binary_model_means_rhet_behav_inter%>% 
  as_tibble() %>% 
  mutate(sample = "Public")

will_challenge_means_rhet_behav_inter<- rbind(tt_will_challenge_binary_model_means_rhet_behav_inter, dl_will_challenge_binary_model_means_rhet_behav_inter) %>% mutate(DV = "Revise int'l order")
will_challenge_contrasts_rhet_behav_inter<- rbind(tt_will_challenge_binary_model_contrasts_rhet_behav_inter, dl_will_challenge_binary_model_contrasts_rhet_behav_inter) %>% mutate(DV = "Revise int'l order")
will_challenge_contrasts_rhet_behav_wbase<- rbind(tt_will_challenge_binary_model_contrasts_rhet_behav_wbase, dl_will_challenge_binary_model_contrasts_rhet_behav_wbase) %>% mutate(DV = "Revise int'l order")



#fp influence
#elites
tt_elite_influence_binary_model_means_rhet_behav_inter<- emmeans(tt_elite_influence_binary_model, ~ rhet_treat*behav_treat)
tt_elite_influence_binary_model_contrasts_rhet_behav_inter<- contrast(infer=TRUE,tt_elite_influence_binary_model_means_rhet_behav_inter, interaction = c(rhet_treat = "pairwise"), by = "behav_treat")  %>% 
  as_tibble() %>%
  mutate(sample = "Elites")
tt_elite_influence_binary_model_contrasts_rhet_behav_wbase<- contrast(infer=TRUE,tt_elite_influence_binary_model_means_rhet_behav_inter, "trt.vs.ctrl", combine = TRUE)  %>% 
  as_tibble() %>%
  mutate(sample = "Elites")
tt_elite_influence_binary_model_means_rhet_behav_inter<- tt_elite_influence_binary_model_means_rhet_behav_inter%>%
  as_tibble() %>%
  mutate(sample = "Elites") 

#public
dl_elite_influence_binary_model_means_rhet_behav_inter<- emmeans(dl_elite_influence_binary_model, ~ rhet_treat*behav_treat) 
dl_elite_influence_binary_model_contrasts_rhet_behav_inter<- contrast(infer=TRUE,dl_elite_influence_binary_model_means_rhet_behav_inter, interaction = c(rhet_treat = "pairwise"), by = "behav_treat") %>% 
  as_tibble() %>% 
  mutate(sample = "Public")
dl_elite_influence_binary_model_contrasts_rhet_behav_wbase<- contrast(infer=TRUE,dl_elite_influence_binary_model_means_rhet_behav_inter, "trt.vs.ctrl", combine = TRUE) %>% 
  as_tibble() %>% 
  mutate(sample = "Public")
dl_elite_influence_binary_model_means_rhet_behav_inter<- dl_elite_influence_binary_model_means_rhet_behav_inter%>% 
  as_tibble() %>% 
  mutate(sample = "Public")

elite_influence_means_rhet_behav_inter<- rbind(tt_elite_influence_binary_model_means_rhet_behav_inter, dl_elite_influence_binary_model_means_rhet_behav_inter) %>% mutate(DV = "Influence recipient FP")
elite_influence_contrasts_rhet_behav_inter<- rbind(tt_elite_influence_binary_model_contrasts_rhet_behav_inter, dl_elite_influence_binary_model_contrasts_rhet_behav_inter) %>% mutate(DV = "Influence recipient FP")
elite_influence_contrasts_rhet_behav_wbase<- rbind(tt_elite_influence_binary_model_contrasts_rhet_behav_wbase, dl_elite_influence_binary_model_contrasts_rhet_behav_wbase) %>% mutate(DV = "Influence recipient FP")



#should have more influence
#elites
tt_should_more_influence_binary_model_means_rhet_behav_inter<- emmeans(tt_should_more_influence_binary_model, ~ rhet_treat*behav_treat)
tt_should_more_influence_binary_model_contrasts_rhet_behav_inter<- contrast(infer=TRUE,tt_should_more_influence_binary_model_means_rhet_behav_inter, interaction = c(rhet_treat = "pairwise"), by = "behav_treat")  %>% 
  as_tibble() %>%
  mutate(sample = "Elites")
tt_should_more_influence_binary_model_contrasts_rhet_behav_wbase<- contrast(infer=TRUE,tt_should_more_influence_binary_model_means_rhet_behav_inter, "trt.vs.ctrl", combine = TRUE)  %>% 
  as_tibble() %>%
  mutate(sample = "Elites")
tt_should_more_influence_binary_model_means_rhet_behav_inter<- tt_should_more_influence_binary_model_means_rhet_behav_inter%>%
  as_tibble() %>%
  mutate(sample = "Elites") 

#public
dl_should_more_influence_binary_model_means_rhet_behav_inter<- emmeans(dl_should_more_influence_binary_model, ~ rhet_treat*behav_treat) 
dl_should_more_influence_binary_model_contrasts_rhet_behav_inter<- contrast(infer=TRUE,dl_should_more_influence_binary_model_means_rhet_behav_inter, interaction = c(rhet_treat = "pairwise"), by = "behav_treat") %>% 
  as_tibble() %>% 
  mutate(sample = "Public")
dl_should_more_influence_binary_model_contrasts_rhet_behav_wbase<- contrast(infer=TRUE,dl_should_more_influence_binary_model_means_rhet_behav_inter, "trt.vs.ctrl", combine = TRUE) %>% 
  as_tibble() %>% 
  mutate(sample = "Public")
dl_should_more_influence_binary_model_means_rhet_behav_inter<- dl_should_more_influence_binary_model_means_rhet_behav_inter%>% 
  as_tibble() %>% 
  mutate(sample = "Public")

more_influence_means_rhet_behav_inter<- rbind(tt_should_more_influence_binary_model_means_rhet_behav_inter, dl_should_more_influence_binary_model_means_rhet_behav_inter) %>% mutate(DV = "Should have more influence")
more_influence_contrasts_rhet_behav_inter<- rbind(tt_should_more_influence_binary_model_contrasts_rhet_behav_inter, dl_should_more_influence_binary_model_contrasts_rhet_behav_inter) %>% mutate(DV = "Should have more influence")
more_influence_contrasts_rhet_behav_wbase<- rbind(tt_should_more_influence_binary_model_contrasts_rhet_behav_wbase, dl_should_more_influence_binary_model_contrasts_rhet_behav_wbase) %>% mutate(DV = "Should have more influence")


#elite only 
#public in recipient countries 
tt_popular_influence_binary_model_means_rhet_behav_inter<- emmeans(tt_popular_influence_binary_model, ~ rhet_treat*behav_treat)
tt_popular_influence_binary_model_contrasts_rhet_behav_inter<- contrast(infer=TRUE,tt_popular_influence_binary_model_means_rhet_behav_inter, interaction = c(rhet_treat = "pairwise"), by = "behav_treat")  %>% 
  as_tibble() %>%
  mutate(sample = "Elites", DV = "Public influence")
tt_popular_influence_binary_model_contrasts_rhet_behav_wbase<- contrast(infer=TRUE,tt_popular_influence_binary_model_means_rhet_behav_inter, "trt.vs.ctrl", combine = TRUE)  %>% 
  as_tibble() %>%
  mutate(sample = "Elites", DV = "Public influence")
tt_popular_influence_binary_model_means_rhet_behav_inter<- tt_popular_influence_binary_model_means_rhet_behav_inter%>%
  as_tibble() %>%
  mutate(sample = "Elites", DV = "Public influence") 


#public only
#responsible stakeholder
dl_responsible_stakeholder_binary_model_means_rhet_behav_inter<- emmeans(dl_responsible_stakeholder_binary_model, ~ rhet_treat*behav_treat) 
dl_responsible_stakeholder_binary_model_contrasts_rhet_behav_inter<- contrast(infer=TRUE,dl_responsible_stakeholder_binary_model_means_rhet_behav_inter, interaction = c(rhet_treat = "pairwise"), by = "behav_treat") %>% 
  as_tibble() %>% 
  mutate(sample = "Public", DV = "Responsible stakeholder")
dl_responsible_stakeholder_binary_model_contrasts_rhet_behav_wbase<- contrast(infer=TRUE,dl_responsible_stakeholder_binary_model_means_rhet_behav_inter,  "trt.vs.ctrl", combine = TRUE) %>% 
  as_tibble() %>% 
  mutate(sample = "Public", DV = "Responsible stakeholder")
dl_responsible_stakeholder_binary_model_means_rhet_behav_inter<- dl_responsible_stakeholder_binary_model_means_rhet_behav_inter%>% 
  as_tibble() %>% 
  mutate(sample = "Public", DV = "Responsible stakeholder")


#threaten us influence
dl_threaten_us_influence_binary_model_means_rhet_behav_inter<- emmeans(dl_threaten_us_influence_binary_model, ~ rhet_treat*behav_treat) 
dl_threaten_us_influence_binary_model_contrasts_rhet_behav_inter<- contrast(infer=TRUE,dl_threaten_us_influence_binary_model_means_rhet_behav_inter, interaction = c(rhet_treat = "pairwise"), by = "behav_treat") %>% 
  as_tibble() %>% 
  mutate(sample = "Public", DV = "Threaten US influence")
dl_threaten_us_influence_binary_model_contrasts_rhet_behav_wbase<- contrast(infer=TRUE,dl_threaten_us_influence_binary_model_means_rhet_behav_inter,"trt.vs.ctrl", combine = TRUE) %>% 
  as_tibble() %>% 
  mutate(sample = "Public", DV = "Threaten US influence")
dl_threaten_us_influence_binary_model_means_rhet_behav_inter<- dl_threaten_us_influence_binary_model_means_rhet_behav_inter%>% 
  as_tibble() %>% 
  mutate(sample = "Public", DV = "Threaten US influence")



combined_means_rhet_behav_inter<- rbind(nat_sec_means_rhet_behav_inter, will_challenge_means_rhet_behav_inter, elite_influence_means_rhet_behav_inter, more_influence_means_rhet_behav_inter)
combined_contrasts_rhet_behav_inter<- rbind(nat_sec_contrasts_rhet_behav_inter, will_challenge_contrasts_rhet_behav_inter, elite_influence_contrasts_rhet_behav_inter, more_influence_contrasts_rhet_behav_inter)
combined_contrasts_rhet_behav_wbase<- rbind(nat_sec_contrasts_rhet_behav_wbase, will_challenge_contrasts_rhet_behav_wbase, elite_influence_contrasts_rhet_behav_wbase, more_influence_contrasts_rhet_behav_wbase)



combined_contrasts_for_text_rhet_behav_wbase<- combined_contrasts_rhet_behav_wbase%>% 
  mutate(estimate = round(estimate, 1), lower.CL = round(lower.CL, 1),  upper.CL = round(upper.CL, 1), p.value = format.pval(pv=p.value, digits=3, eps = 0.001,  nsmall = 3)) %>%
  arrange(sample) %>%
  mutate(contrast_label = case_when( contrast == "Status Quo Revisionist - Revisionist Revisionist" ~ "2) SQ Rhetoric & Rev. Behavior",
                                     contrast == "Revisionist Status Quo - Revisionist Revisionist" ~ "3) Rev. Rhetoric & SQ Behavior",
                                     contrast == "Status Quo Status Quo - Revisionist Revisionist" ~ "4) SQ Rhetoric & SQ Behavior"))
combined_contrasts_for_text_rhet_behav_wbase


  


# Build Figure 1. 
data_for_figure1_top <- combined_means_behav %>%
  filter(DV == "Threat to U.S. security" | DV == "Revise int'l order" | DV == "Should have more influence") %>%
  mutate(DV_label = case_when(DV == "Threat to U.S. security" ~ "a) ...is a threat to U.S. security",
                              DV == "Revise int'l order" ~ "b) ...will revise int'l order",
                              DV == "Should have more influence" ~ "c) ...should have more influence")) 



#Top of Figure 1
figure1_top <- ggplot(data = data_for_figure1_top , aes(x = DV_label, y=emmean, ymin = lower.CL, ymax = upper.CL, group=behav_treat, shape=behav_treat)) +
  geom_pointrange(position = position_dodge(width=.5) ) +
  facet_grid(sample~. ) +
  geom_text(aes(label=round(emmean, digits=1)), size=2, color="black", position = position_dodge(width=1.25)) +
  plot_theme + 
  ylab("Percent of respondents in agreement") +
  theme_linedraw() +    xlab("") + theme(panel.grid.major.y = element_blank(), panel.grid.major.x = element_blank(), panel.grid.minor.y = element_blank()) +
  geom_vline(xintercept = 1.5, color="#CCCCCC") +
  geom_vline(xintercept = 2.5, , color="#CCCCCC") + labs(shape="Bevhavior") +
  coord_flip() + ggtitle("The country described in the scenario...") 
figure1_top



data_for_figure1_bottom <- combined_means_rhet %>%
  filter(DV == "Threat to U.S. security" | DV == "Revise int'l order" | DV == "Should have more influence") %>%
  mutate(DV_label = case_when(DV == "Threat to U.S. security" ~ "a) ...is a threat to U.S. security",
                              DV == "Revise int'l order" ~ "b) ...will revise int'l order",
                              DV == "Should have more influence" ~ "c) ...should have more influence")) 


figure1_bottom <- ggplot(data = data_for_figure1_bottom , aes(x = DV_label, y=emmean, ymin = lower.CL, ymax = upper.CL, group=rhet_treat, shape=rhet_treat)) +
  geom_pointrange(position = position_dodge(width=.5) ) +
  facet_grid(sample~. ) + 
  geom_text(aes(label=round(emmean, digits=1)), size=2, color="black", position = position_dodge(width=1.25)) +
  plot_theme + 
  ylab("Percent of respondents in agreement") + 
  theme_linedraw() +    xlab("") + theme(panel.grid.major.y = element_blank(), panel.grid.major.x = element_blank(), panel.grid.minor.y = element_blank()) +
  geom_vline(xintercept = 1.5, color="#CCCCCC") +
  geom_vline(xintercept = 2.5, , color="#CCCCCC") + labs(shape="Rhetoric") +
  coord_flip() + ggtitle("The country described in the scenario...") 
figure1_bottom


# Combine figure 
figure1_combined <- ggarrange(NULL, figure1_top, NULL , figure1_bottom, 
                              labels = c("","1) Marginal mean agreement by behavior condition", "",  "2) Marginal mean agreement by rhetoric condition"),
                              ncol = 1, nrow = 4, 
                              vjust=-.5, 
                              hjust = -.05,
                              font.label = list(size = 10, face="bold"),
                              heights =c(1, 5, 1, 5))

ggsave("figure1.png", figure1_combined, width=8, height=10, dpi=600)


## Build Figure 2


data_for_figure2_top <- combined_contrasts_for_text_behav %>%
  filter(DV == "Threat to U.S. security" | DV == "Revise int'l order" | DV == "Should have more influence")   %>% 
  mutate(DV_label = case_when(DV == "Threat to U.S. security" ~ "...is a threat to U.S. security",
                              DV == "Revise int'l order" ~ "...will revise int'l order",
                              DV == "Should have more influence" ~ "...should have more influence")) %>% 
  mutate(DV_label = factor(DV_label, levels= c("...is a threat to U.S. security",  "...will revise int'l order", "...should have more influence")))

data_for_figure2_bottom <- combined_contrasts_for_text_rhet %>%
  filter(DV == "Threat to U.S. security" | DV == "Revise int'l order" | DV == "Should have more influence") %>%
  mutate(DV_label = case_when(DV == "Threat to U.S. security" ~ "...is a threat to U.S. security",
                              DV == "Revise int'l order" ~ "...will revise int'l order",
                              DV == "Should have more influence" ~ "...should have more influence")) %>%
  mutate(DV_label = factor(DV_label, levels= c("...is a threat to U.S. security",  "...will revise int'l order", "...should have more influence")))



figure2_top <- ggplot(data = data_for_figure2_top , aes(x = DV_label, y=estimate, ymin = lower.CL, ymax = upper.CL)) +
  geom_pointrange(position = position_dodge(width=.2) ) +
  facet_grid(sample~. ) +
  geom_hline(yintercept=0, color="black") +
  geom_text(aes(label=round(estimate, digits=1)), size=2, nudge_x = .25, color="black") +
  plot_theme + 
  ylab("Effect of revisionist behavior on agreement") +
  xlab("") + scale_y_continuous(limits=c(-31,35)) + 
  theme_linedraw() + 
  coord_flip() + ggtitle("The country described in the scenario...") 
figure2_top

figure2_bottom <- ggplot(data = data_for_figure2_bottom , aes(x = DV_label, y=estimate, ymin = lower.CL, ymax = upper.CL)) +
  geom_pointrange(position = position_dodge(width=.2) ) +
  facet_grid(sample~. ) +
  geom_hline(yintercept=0, color="black") +
  geom_text(aes(label=round(estimate, digits=1)), size=2, nudge_x = .25, color="black") +
  plot_theme + 
  ylab("Effect of revisionist rhetoric on agreement") +
  xlab("") +  
  theme_linedraw() +  
  scale_y_continuous(limits=c(-31,35)) + 
  coord_flip() + ggtitle("The country described in the scenario...") 
figure2_bottom


figure2_combined <- ggarrange(NULL, figure2_top, NULL , figure2_bottom, 
                              labels = c("","1) ATE of revisionist behavior (relative to status quo behavior)", "",  "2) ATE of revisionist rhetoric (relative to status quo rhetoric)"),
                              ncol = 1, nrow = 4, 
                              vjust=-.5, 
                              hjust = -.05,
                              font.label = list(size = 10, face="bold"),
                              heights =c(1, 5, 1, 5))

ggsave("figure2.png", figure2_combined, width=8, height=10, dpi=600)




# Build figure 3
data_for_figure3_te  <- combined_contrasts_for_text_rhet_behav_wbase %>%   
  filter(DV == "Threat to U.S. security" | DV == "Revise int'l order" | DV == "Should have more influence") %>%
  mutate(DV_label = case_when(DV == "Threat to U.S. security" ~ "...is a threat to U.S. security",
                              DV == "Revise int'l order" ~ "...will revise int'l order",
                              DV == "Should have more influence" ~ "...should have more influence")) 

baseline_vals <- tibble( estimate = rep(0, 6), DV_label = c(unique(data_for_figure3_te$DV_label), unique(data_for_figure3_te$DV_label) ),  contrast_label = "1) Rev. Rhetoric & Rev. Behavior", lower.CL = 0, upper.CL = 0, sample = c(rep("Public",3), rep("Elites",3)))

data_for_figure3_te <- bind_rows(data_for_figure3_te, baseline_vals) %>%
  mutate(contrast_label = factor(contrast_label, levels = c( "1) Rev. Rhetoric & Rev. Behavior", "2) SQ Rhetoric & Rev. Behavior",  "3) Rev. Rhetoric & SQ Behavior",  "4) SQ Rhetoric & SQ Behavior"))) %>%
  mutate(DV_label = factor(DV_label, levels= c("...is a threat to U.S. security",  "...will revise int'l order", "...should have more influence")))


figure3 <- ggplot(data = data_for_figure3_te , aes(x = contrast_label, y=estimate, ymin = lower.CL, ymax = upper.CL)) +
  geom_hline(yintercept=0, color="black") +
  geom_pointrange(position = position_dodge(width=.2) ) +
  facet_grid(sample~DV_label ) +
  geom_text(aes(label=round(estimate, digits=1)), size=2.5, nudge_x = .25, color="black") +
  plot_theme + 
  ylab("Treatment effect") +
  xlab("") +  
  theme_linedraw() +  
  coord_flip() + ggtitle("The country described in the scenario...") 
ggsave("figure3.png", figure3, width=8, height=5, dpi=600)







## influence 
influence_combined_means_rhet_behav_inter<- rbind(elite_influence_means_rhet_behav_inter, tt_popular_influence_binary_model_means_rhet_behav_inter)

data_for_figure4 <- influence_combined_means_rhet_behav_inter %>% 
  mutate(DV_label = case_when(DV == "Influence recipient FP" ~ "...can influence recipient foreign policy",
                              DV == "Public influence" ~ "...will be viewed more favorably by recipient publics ")) %>%
  mutate(rhet_treat_label = case_when(rhet_treat == "Revisionist" ~  "Revisionist",
                                      rhet_treat == "Status Quo" ~  "Status quo")) %>%
  mutate(behav_treat_label = case_when(behav_treat == "Revisionist" ~  "Revisionist behavior",
                                       behav_treat == "Status Quo" ~  "Status quo behavior"))



figure4 <- ggplot(data = filter(data_for_figure4), aes(x = behav_treat_label, y=emmean, ymin = lower.CL, ymax = upper.CL, group=rhet_treat, shape=rhet_treat_label)) +
  geom_pointrange(position = position_dodge(width=.5) ) +
  facet_wrap(DV_label~sample, ncol=1) + 
  geom_text(aes(label=round(emmean, digits=1)), size=2, color="black", position = position_dodge(width=1.25)) +
  plot_theme + 
  ylab("Percent of respondents in agreement") +
  xlab("") + scale_y_continuous(limits=c(0,100)) +  
  theme_linedraw() +    xlab("") + theme(panel.grid.major.y = element_blank(), panel.grid.major.x = element_blank(), panel.grid.minor.y = element_blank()) +
  geom_vline(xintercept = 1.5, color="#CCCCCC") + 
  labs(shape="Rhetoric") +
  coord_flip() + ggtitle("The country described in the scenario...") 
figure4
ggsave("figure4.png", figure4, width=6, height=8, dpi=600)
