Download 23/replication_package/Code/replicate_fig_3.R from chuxuan/REPRO-Bench: direct link, hf CLI and curl.
- Browser
- Download file 14.1 kB
-
https://huggingface.co/datasets/chuxuan/REPRO-Bench/resolve/main/23/replication_package/Code/replicate_fig_3.R
- Command line
-
hf download hf://datasets/chuxuan/REPRO-Bench/23/replication_package/Code/replicate_fig_3.R
-
curl -L -o replicate_fig_3.R https://huggingface.co/datasets/chuxuan/REPRO-Bench/resolve/main/23/replication_package/Code/replicate_fig_3.R
14.1 kB
| ##--##--##--## | |
| ## Figure 3 | |
| ##--##--##--## | |
| us_survey_wave1$identity_protesters_fac = as.factor(us_survey_wave1$identity_protesters) | |
| levels(us_survey_wave1$identity_protesters_fac) = c("White", "Black") | |
| us_survey_wave1$tactic_fac = as.factor(us_survey_wave1$tactic) | |
| levels(us_survey_wave1$tactic_fac) = c("March in streets", "Shut down traffic", "Destroy police cars") | |
| isr_survey_wave1$identity_protesters_fac = as.factor(isr_survey_wave1$identity_protesters) | |
| levels(isr_survey_wave1$identity_protesters_fac) = c("White", "Ethiopian", "Arab") | |
| isr_survey_wave1$tactic_fac = as.factor(isr_survey_wave1$tactic) | |
| levels(isr_survey_wave1$tactic_fac) = c("March in streets", "Shut down traffic", "Destroy garbage cans") | |
| ## US sample | |
| us_survey_wave1$degree_violence_std = scale(us_survey_wave1$degree_violence) | |
| us_survey_wave1$police_action_required_std = scale(us_survey_wave1$police_action_required) | |
| us_survey_wave1$recall_violence2_std = scale(us_survey_wave1$recall_violence2) | |
| march1 = lm_robust(degree_violence_std ~ identity_protesters_fac, data=us_survey_wave1[us_survey_wave1$tactic==0,], weights=weight) | |
| shut1 = lm_robust(degree_violence_std ~ identity_protesters_fac, data=us_survey_wave1[us_survey_wave1$tactic==1,], weights=weight) | |
| destroy1 = lm_robust(degree_violence_std ~ identity_protesters_fac , data=us_survey_wave1[us_survey_wave1$tactic==2,], weights=weight) | |
| march2 = lm_robust(police_action_required_std ~ identity_protesters_fac, data=us_survey_wave1[us_survey_wave1$tactic==0,], weights=weight) | |
| shut2 = lm_robust(police_action_required_std ~ identity_protesters_fac, data=us_survey_wave1[us_survey_wave1$tactic==1,], weights=weight) | |
| destroy2 = lm_robust(police_action_required_std ~ identity_protesters_fac, data=us_survey_wave1[us_survey_wave1$tactic==2,], weights=weight) | |
| march3 = lm_robust(recall_violence2_std ~ identity_protesters_fac, data=us_survey_wave1[us_survey_wave1$tactic==0,], weights=weight) | |
| shut3 = lm_robust(recall_violence2_std ~ identity_protesters_fac, data=us_survey_wave1[us_survey_wave1$tactic==1,], weights=weight) | |
| destroy3 = lm_robust(recall_violence2_std ~ identity_protesters_fac , data=us_survey_wave1[us_survey_wave1$tactic==2,], weights=weight) | |
| # Plot differences | |
| term_degree_violence = c(march1$coefficients[2], shut1$coefficients[2], destroy1$coefficients[2]) | |
| se_degree_violence = c(march1$std.error[2], shut1$std.error[2], destroy1$std.error[2]) | |
| statistic_degree_violence = c(march1$statistic[2], shut1$statistic[2], destroy1$statistic[2]) | |
| pval_degree_violence = c(march1$p.value[2], shut1$p.value[2], destroy1$p.value[2]) | |
| term = c("1) Minority: March in streets", "2) Minority: Shut down traffic", "3) Minority: Destroy police cars / garbage cans") | |
| degree_violence = as.data.frame(cbind(term_degree_violence, se_degree_violence, statistic_degree_violence, pval_degree_violence)) | |
| degree_violence = cbind(degree_violence, term) | |
| colnames(degree_violence) = c("estimate", "std.error", "statistic", "p.value", "term") | |
| rownames(degree_violence) = term | |
| degree_violence$model = "Perceived degree of violence" | |
| term_police_action_required = c(march2$coefficients[2], shut2$coefficients[2], destroy2$coefficients[2]) | |
| se_police_action_required = c(march2$std.error[2], shut2$std.error[2], destroy2$std.error[2]) | |
| statistic_police_action_required = c(march2$statistic[2], shut2$statistic[2], destroy2$statistic[2]) | |
| pval_police_action_required = c(march2$p.value[2], shut2$p.value[2], destroy2$p.value[2]) | |
| term = c("1) Minority: March in streets", "2) Minority: Shut down traffic", "3) Minority: Destroy police cars / garbage cans") | |
| police_action_required = as.data.frame(cbind(term_police_action_required, se_police_action_required, statistic_police_action_required, pval_police_action_required)) | |
| police_action_required = cbind(police_action_required, term) | |
| colnames(police_action_required) = c("estimate", "std.error", "statistic", "p.value", "term") | |
| rownames(police_action_required) = term | |
| police_action_required$model = "Police action required" | |
| term_recall_violence = c(march3$coefficients[2], shut3$coefficients[2], destroy3$coefficients[2]) | |
| se_recall_violence = c(march3$std.error[2], shut3$std.error[2], destroy3$std.error[2]) | |
| statistic_recall_violence = c(march3$statistic[2], shut3$statistic[2], destroy3$statistic[2]) | |
| pval_recall_violence = c(march3$p.value[2], shut3$p.value[2], destroy3$p.value[2]) | |
| term = c("1) Minority: March in streets", "2) Minority: Shut down traffic", "3) Minority: Destroy police cars / garbage cans") | |
| recall_violence = as.data.frame(cbind(term_recall_violence, se_recall_violence, statistic_recall_violence, pval_recall_violence)) | |
| recall_violence = cbind(recall_violence, term) | |
| colnames(recall_violence) = c("estimate", "std.error", "statistic", "p.value", "term") | |
| rownames(recall_violence) = term | |
| recall_violence$model = "Recall violence" | |
| differences_us = rbind(degree_violence, police_action_required, recall_violence) | |
| ## Israel respondents | |
| isr_survey_wave1$degree_violence_std = scale(isr_survey_wave1$degree_violence) | |
| isr_survey_wave1$police_action_required_std = scale(isr_survey_wave1$police_action_required) | |
| isr_survey_wave1$recall_violence2_std = scale(isr_survey_wave1$recall_violence2) | |
| march1 = lm_robust(degree_violence_std ~ identity_protesters_fac, data=isr_survey_wave1[isr_survey_wave1$tactic==0,], weights=weight) | |
| shut1 = lm_robust(degree_violence_std ~ identity_protesters_fac, data=isr_survey_wave1[isr_survey_wave1$tactic==1,], weights=weight) | |
| destroy1 = lm_robust(degree_violence_std ~ identity_protesters_fac , data=isr_survey_wave1[isr_survey_wave1$tactic==2,], weights=weight) | |
| march2 = lm_robust(police_action_required_std ~ identity_protesters_fac, data=isr_survey_wave1[isr_survey_wave1$tactic==0,], weights=weight) | |
| shut2 = lm_robust(police_action_required_std ~ identity_protesters_fac, data=isr_survey_wave1[isr_survey_wave1$tactic==1,], weights=weight) | |
| destroy2 = lm_robust(police_action_required_std ~ identity_protesters_fac, data=isr_survey_wave1[isr_survey_wave1$tactic==2,], weights=weight) | |
| march3 = lm_robust(recall_violence2_std ~ identity_protesters_fac, data=isr_survey_wave1[isr_survey_wave1$tactic==0,], weights=weight) | |
| shut3 = lm_robust(recall_violence2_std ~ identity_protesters_fac, data=isr_survey_wave1[isr_survey_wave1$tactic==1,], weights=weight) | |
| destroy3 = lm_robust(recall_violence2_std ~ identity_protesters_fac , data=isr_survey_wave1[isr_survey_wave1$tactic==2,], weights=weight) | |
| # Ethiopian protesters | |
| term_degree_violence = c(march1$coefficients[2], shut1$coefficients[2], destroy1$coefficients[2]) | |
| se_degree_violence = c(march1$std.error[2], shut1$std.error[2], destroy1$std.error[2]) | |
| statistic_degree_violence = c(march1$statistic[2], shut1$statistic[2], destroy1$statistic[2]) | |
| pval_degree_violence = c(march1$p.value[2], shut1$p.value[2], destroy1$p.value[2]) | |
| term = c("1) Minority: March in streets", "2) Minority: Shut down traffic", "3) Minority: Destroy police cars / garbage cans") | |
| degree_violence = as.data.frame(cbind(term_degree_violence, se_degree_violence, statistic_degree_violence, pval_degree_violence)) | |
| degree_violence = cbind(degree_violence, term) | |
| colnames(degree_violence) = c("estimate", "std.error", "statistic", "p.value", "term") | |
| rownames(degree_violence) = term | |
| degree_violence$model = "Perceived degree of violence" | |
| term_police_action_required = c(march2$coefficients[2], shut2$coefficients[2], destroy2$coefficients[2]) | |
| se_police_action_required = c(march2$std.error[2], shut2$std.error[2], destroy2$std.error[2]) | |
| statistic_police_action_required = c(march2$statistic[2], shut2$statistic[2], destroy2$statistic[2]) | |
| pval_police_action_required = c(march2$p.value[2], shut2$p.value[2], destroy2$p.value[2]) | |
| term = c("1) Minority: March in streets", "2) Minority: Shut down traffic", "3) Minority: Destroy police cars / garbage cans") | |
| police_action_required = as.data.frame(cbind(term_police_action_required, se_police_action_required, statistic_police_action_required, pval_police_action_required)) | |
| police_action_required = cbind(police_action_required, term) | |
| colnames(police_action_required) = c("estimate", "std.error", "statistic", "p.value", "term") | |
| rownames(police_action_required) = term | |
| police_action_required$model = "Police action required" | |
| term_recall_violence = c(march3$coefficients[2], shut3$coefficients[2], destroy3$coefficients[2]) | |
| se_recall_violence = c(march3$std.error[2], shut3$std.error[2], destroy3$std.error[2]) | |
| statistic_recall_violence = c(march3$statistic[2], shut3$statistic[2], destroy3$statistic[2]) | |
| pval_recall_violence = c(march3$p.value[2], shut3$p.value[2], destroy3$p.value[2]) | |
| term = c("1) Minority: March in streets", "2) Minority: Shut down traffic", "3) Minority: Destroy police cars / garbage cans") | |
| recall_violence = as.data.frame(cbind(term_recall_violence, se_recall_violence, statistic_recall_violence, pval_recall_violence)) | |
| recall_violence = cbind(recall_violence, term) | |
| colnames(recall_violence) = c("estimate", "std.error", "statistic", "p.value", "term") | |
| rownames(recall_violence) = term | |
| recall_violence$model = "Recall violence" | |
| differences_isr_black = rbind(degree_violence, police_action_required, recall_violence) | |
| term_degree_violence = c(march1$coefficients[3], shut1$coefficients[3], destroy1$coefficients[3]) | |
| se_degree_violence = c(march1$std.error[3], shut1$std.error[3], destroy1$std.error[3]) | |
| statistic_degree_violence = c(march1$statistic[3], shut1$statistic[3], destroy1$statistic[3]) | |
| pval_degree_violence = c(march1$p.value[3], shut1$p.value[3], destroy1$p.value[3]) | |
| term = c("1) Minority: March in streets", "2) Minority: Shut down traffic", "3) Minority: Destroy police cars / garbage cans") | |
| degree_violence = as.data.frame(cbind(term_degree_violence, se_degree_violence, statistic_degree_violence, pval_degree_violence)) | |
| degree_violence = cbind(degree_violence, term) | |
| colnames(degree_violence) = c("estimate", "std.error", "statistic", "p.value", "term") | |
| rownames(degree_violence) = term | |
| degree_violence$model = "Perceived degree of violence" | |
| term_police_action_required = c(march2$coefficients[3], shut2$coefficients[3], destroy2$coefficients[3]) | |
| se_police_action_required = c(march2$std.error[3], shut2$std.error[3], destroy2$std.error[3]) | |
| statistic_police_action_required = c(march2$statistic[3], shut2$statistic[3], destroy2$statistic[3]) | |
| pval_police_action_required = c(march2$p.value[3], shut2$p.value[3], destroy2$p.value[3]) | |
| term = c("1) Minority: March in streets", "2) Minority: Shut down traffic", "3) Minority: Destroy police cars / garbage cans") | |
| police_action_required = as.data.frame(cbind(term_police_action_required, se_police_action_required, statistic_police_action_required, pval_police_action_required)) | |
| police_action_required = cbind(police_action_required, term) | |
| colnames(police_action_required) = c("estimate", "std.error", "statistic", "p.value", "term") | |
| rownames(police_action_required) = term | |
| police_action_required$model = "Police action required" | |
| term_recall_violence = c(march3$coefficients[3], shut3$coefficients[3], destroy3$coefficients[3]) | |
| se_recall_violence = c(march3$std.error[3], shut3$std.error[3], destroy3$std.error[3]) | |
| statistic_recall_violence = c(march3$statistic[3], shut3$statistic[3], destroy3$statistic[3]) | |
| pval_recall_violence = c(march3$p.value[3], shut3$p.value[3], destroy3$p.value[3]) | |
| term = c("1) Minority: March in streets", "2) Minority: Shut down traffic", "3) Minority: Destroy police cars / garbage cans") | |
| recall_violence = as.data.frame(cbind(term_recall_violence, se_recall_violence, statistic_recall_violence, pval_recall_violence)) | |
| recall_violence = cbind(recall_violence, term) | |
| colnames(recall_violence) = c("estimate", "std.error", "statistic", "p.value", "term") | |
| rownames(recall_violence) = term | |
| recall_violence$model = "Recall violence" | |
| differences_isr_arab = rbind(degree_violence, police_action_required, recall_violence) | |
| ## Result tables for plot | |
| differences_us2 = differences_us | |
| differences_us2$submodel = differences_us2$term | |
| differences_us2$term = "Perception of Blacks \n(United States)" | |
| differences_isr_black2 = differences_isr_black | |
| differences_isr_black2$submodel = differences_isr_black2$term | |
| differences_isr_black2$term = "Perception of Ethiopians \n(Israel)" | |
| differences_isr_arab2 = differences_isr_arab | |
| differences_isr_arab2$submodel = differences_isr_arab2$term | |
| differences_isr_arab2$term = "Perception of Arabs \n(Israel)" | |
| diffs_sm = rbind(differences_us2, differences_isr_arab2, differences_isr_black2) | |
| rownames(diffs_sm) = 1:nrow(diffs_sm) | |
| results_df <- data.frame(term = diffs_sm$term, | |
| estimate = diffs_sm$estimate, | |
| std.error = diffs_sm$std.error, | |
| model = diffs_sm$model, | |
| submodel = as.character(diffs_sm$submodel), | |
| stringsAsFactors = FALSE) | |
| results_df$submodel[results_df$submodel=="1) Minority: March in streets"] = "March in streets" | |
| results_df$submodel[results_df$submodel=="2) Minority: Shut down traffic"] = "Shut down traffic" | |
| results_df$submodel[results_df$submodel=="3) Minority: Destroy police cars / garbage cans"] = "Destroy property" | |
| results_df$model[results_df$model=="Perceived degree of violence"] = "1. Perceived degree \nof violence" | |
| results_df$model[results_df$model=="Police action required"] = "3. Police action \nrequired" | |
| results_df$model[results_df$model=="Recall violence"] = "2. Recall \nviolence" | |
| small_multiple(results_df, dot_args = list(aes(shape = submodel))) + | |
| ylab("Coefficient Estimate (Std. Dev. Units)") + theme_bw()+ | |
| geom_hline(yintercept = 0, colour = "grey60", linetype = 2) + | |
| #theme(plot.margin=unit(c(0.4,0.1,2.6,1),"cm"))+ | |
| theme(legend.position = "bottom", | |
| legend.justification=c(0, 0), | |
| # legend.background = element_rect(color="white"), | |
| legend.spacing = unit(-4, "pt"), | |
| legend.key.size = unit(10, "pt"))+ | |
| scale_shape_discrete(name = "Protester Tactic") + | |
| scale_color_manual(values=c("#999999", "#E69F00", "#56B4E9"), name = "Protester Tactic") | |
| ggsave(filename="Figures/fig_3.pdf", width=6, height=6) | |
| table_a14 = results_df | |