Download 23/replication_package/Code/replicate_fig_1.R from chuxuan/REPRO-Bench: direct link, hf CLI and curl.
- Browser
- Download file 3.75 kB
-
https://huggingface.co/datasets/chuxuan/REPRO-Bench/resolve/main/23/replication_package/Code/replicate_fig_1.R
- Command line
-
hf download hf://datasets/chuxuan/REPRO-Bench/23/replication_package/Code/replicate_fig_1.R
-
curl -L -o replicate_fig_1.R https://huggingface.co/datasets/chuxuan/REPRO-Bench/resolve/main/23/replication_package/Code/replicate_fig_1.R
3.75 kB
| ##--##--##--## | |
| ## Figure 1 | |
| ##--##--##--## | |
| # Status (excluded, not excluded) | |
| nv_status = lm(success ~ EPR_STATUS_EXCL + EPR_GROUPSIZE + POP_LOG_LAG_EXT + GDPPC_LOG_LAG_EXT + VDEM_POLYARCHY_LAG + VDEM_PHYSINT_LAG + EPR_TEK_EGIP + EPR_DOWNGRADED5 + HORIZ_INEQ + NVYEARS + I(NVYEARS^2) + I(NVYEARS^3) + VYEARS + I(VYEARS^2) + I(VYEARS^3) , data= EBCR_EPR_NAVCO2[EBCR_EPR_NAVCO2$INIT_NV_ONSET==1,]) | |
| v_status = lm(success ~ EPR_STATUS_EXCL + EPR_GROUPSIZE + POP_LOG_LAG_EXT + GDPPC_LOG_LAG_EXT + VDEM_POLYARCHY_LAG + VDEM_PHYSINT_LAG + EPR_TEK_EGIP + EPR_DOWNGRADED5 + HORIZ_INEQ + NVYEARS + I(NVYEARS^2) + I(NVYEARS^3) + VYEARS + I(VYEARS^2) + I(VYEARS^3) , data= EBCR_EPR_NAVCO2[EBCR_EPR_NAVCO2$INIT_V_ONSET==1,]) | |
| preds_nv = ggpredict(nv_status, terms = c("EPR_STATUS_EXCL")) | |
| preds_nv$tactic = "Non-violent" | |
| preds_v = ggpredict(v_status, terms = c("EPR_STATUS_EXCL")) | |
| preds_v$tactic = "Violent" | |
| preds = rbind(preds_nv, preds_v) | |
| preds$tactic <- factor(preds$tactic, levels = c("Violent", "Non-violent")) | |
| preds$Status = "Minority/disadvantaged" | |
| preds$Status[preds$x==0] = "Majority/dominant" | |
| xtable(preds[,-1], digits=2) | |
| preds = as.data.frame(preds) | |
| preds$Status = as.factor(preds$Status) | |
| status = ggplot(preds, aes(x = tactic, y = predicted, group=Status)) + | |
| geom_line(aes(color=Status))+ geom_errorbar(aes(color = Status), width = 0, ymin=preds$conf.low, ymax=preds$conf.high)+ | |
| geom_point(aes(color=Status, shape=Status), size=3) + ylim(-0.1,0.5) + theme_bw() + | |
| scale_colour_grey(start = 0.1, end = 0.65) + geom_hline(yintercept=0, linetype="dashed")+ | |
| ylab("Pr(Campaign Success)") + xlab("Tactic") +ggtitle("(A) Group Status") + | |
| theme(legend.position="none") | |
| ## Size (above and below the mean of the distribution) | |
| EBCR_EPR_NAVCO2$small_size = NA | |
| EBCR_EPR_NAVCO2$small_size[EBCR_EPR_NAVCO2$EPR_GROUPSIZE < mean(EBCR_EPR_NAVCO2$EPR_GROUPSIZE, na.rm=T)] = 1 | |
| EBCR_EPR_NAVCO2$small_size[EBCR_EPR_NAVCO2$EPR_GROUPSIZE >= mean(EBCR_EPR_NAVCO2$EPR_GROUPSIZE, na.rm=T)] = 0 | |
| nv_size = lm(success ~ small_size + POP_LOG_LAG_EXT + GDPPC_LOG_LAG_EXT + VDEM_POLYARCHY_LAG + VDEM_PHYSINT_LAG + EPR_TEK_EGIP + EPR_DOWNGRADED5 + HORIZ_INEQ + NVYEARS + I(NVYEARS^2) + I(NVYEARS^3) + VYEARS + I(VYEARS^2) + I(VYEARS^3) , data= EBCR_EPR_NAVCO2[EBCR_EPR_NAVCO2$INIT_NV_ONSET==1,]) | |
| v_size = lm(success ~ small_size + POP_LOG_LAG_EXT + GDPPC_LOG_LAG_EXT + VDEM_POLYARCHY_LAG + VDEM_PHYSINT_LAG + EPR_TEK_EGIP + EPR_DOWNGRADED5 + HORIZ_INEQ + NVYEARS + I(NVYEARS^2) + I(NVYEARS^3) + VYEARS + I(VYEARS^2) + I(VYEARS^3) , data= EBCR_EPR_NAVCO2[EBCR_EPR_NAVCO2$INIT_V_ONSET==1,]) | |
| preds_nv = ggpredict(nv_size, terms = c("small_size")) | |
| preds_nv$tactic = "Non-violent" | |
| preds_v = ggpredict(v_size, terms = c("small_size")) | |
| preds_v$tactic = "Violent" | |
| preds = rbind(preds_nv, preds_v) | |
| preds$tactic <- factor(preds$tactic, levels = c("Violent", "Non-violent")) | |
| preds$Status = "Minority/disadvantaged" | |
| preds$Status[preds$x==0] = "Majority/dominant" | |
| preds = as.data.frame(preds) | |
| preds$Status = as.factor(preds$Status) | |
| xtable(preds[,-1], digits=2) | |
| size = ggplot(preds, aes(x = tactic, y = predicted, group=Status)) + | |
| geom_line(aes(color=Status))+ geom_errorbar(aes(color = Status), width = 0, ymin=preds$conf.low, ymax=preds$conf.high)+ | |
| geom_point(aes(color=Status, shape=Status), size=3) + ylim(-0.1,0.5) + theme_bw() + | |
| #scale_color_manual(values=c("#E69F00", "#56B4E9")) + geom_hline(yintercept=0, linetype="dashed")+ | |
| scale_colour_grey(start = 0.1, end = 0.65) + geom_hline(yintercept=0, linetype="dashed")+ | |
| ylab("Pr(Campaign Success)") + xlab("Tactic") +ggtitle("(B) Group Size") + | |
| theme(legend.position="none") | |
| fig1 = grid_arrange_shared_legend(status, size, ncol = 2, nrow = 1) | |
| ggsave(file="Figures/fig_1.pdf", fig1, width=8, height=4) |