Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/svmiller/peacesciencer
Tools and Data for Quantitative Peace Science
https://github.com/svmiller/peacesciencer
eugene peace-science r
Last synced: about 1 month ago
JSON representation
Tools and Data for Quantitative Peace Science
- Host: GitHub
- URL: https://github.com/svmiller/peacesciencer
- Owner: svmiller
- License: gpl-2.0
- Created: 2020-12-12T19:04:32.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2023-04-25T07:54:41.000Z (over 1 year ago)
- Last Synced: 2024-11-28T16:51:22.445Z (about 2 months ago)
- Topics: eugene, peace-science, r
- Language: HTML
- Homepage: http://svmiller.com/peacesciencer
- Size: 80.1 MB
- Stars: 27
- Watchers: 2
- Forks: 3
- Open Issues: 5
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
README
---
output: github_document
always_allow_html: TRUE
---# `peacesciencer`: Tools and Data for Quantitative Peace Science
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
``````{r loadstuff, echo=FALSE, results="hide", message=FALSE}
library("badger")
library("tidyverse")
library(kableExtra)
library(peacesciencer)
library(stevemisc)
``````{r, echo = FALSE, results='asis'}
cat(
badge_cran_release("peacesciencer", "green"),
badge_cran_download("peacesciencer", "grand-total", "green"),
badge_cran_download("peacesciencer", "last-month", "green"),
badge_cran_download("peacesciencer", "last-week", "green")
)
````peacesciencer` is an R package including various functions and data sets to allow easier analyses in the field of quantitative peace science. The goal is to provide an R package that reasonably approximates what made EUGene so attractive to scholars working in the field of quantitative peace science in the early 2000s. EUGene shined because it encouraged replications of conflict models while having the user also generate data from scratch. Likewise, this R package will offer tools to approximate what EUGene did within the R environment (i.e. not requiring Windows for installation).
# Installation
You can install this on CRAN, as follows:
```r
install.packages("peacesciencer")```
You can install the development version of this package through the `devtools` package. The development version of the package invariably has more goodies, but may or may not be at various levels of stress-testing.
```r
devtools::install_github("svmiller/peacesciencer")
```# How to Use `{peacesciencer}`
New users should read two things to get started. [The package's website](http://svmiller.com/peacesciencer/index.html) has an exhaustive list and description of [all the functions and data included](http://svmiller.com/peacesciencer/reference/index.html) in the package. [`{peacesciencer}` has a user's guide](http://svmiller.com/peacesciencer/ms.pdf) that is worth reading. The user's guide points to its potential uses and benefits while also offering some encouragement for those completely new to the R programming language. The package is designed to be accessible to those with no prior experience with R, though completely new users who feel lost or overwhelmed should learn about [the "tidy" approach to R](https://www.tidyverse.org/) to help them get started.
The workflow is going to look something like this. First, start with one of two processes to create either dyad-year or state-year data. The dyad-year data are created with the `create_dyadyears()` function. It has a few optional parameters with hidden defaults. The user can specify what kind of state system (`system`) data they want to use---either Correlates of War (`"cow"`) or Gleditsch-Ward (`"gw"`), whether they want to extend the data to the most recently concluded calendar year (`mry`) (i.e. Correlates of War state system membership data are current as of Dec. 31, 2016 and the script can extend that to the end of the most recently concluded calendar year), and whether the user wants directed or non-directed dyad-year data (`directed`).
The `create_stateyears()` works much the same way, though "directed" and "non-directed" make no sense in the state-year context. Both functions default to Correlates of War state system membership data to the most recently concluded calendar year.
Thereafter, the user can specify what additional variables they want added to these dyad-year or state-year data. Do note: the additional functions lean primarily on Correlates of War state code identifiers. Indeed, the bulk of the quantitative peace science data ecosystem is built around the Correlates of War project. The variables the user wants are added in [a "pipe"](https://r4ds.had.co.nz/pipes.html) in a process like this. Do note that the user may want to break up the data-generating process into a few manageable "chunks" (e.g. first generating dyad-year data and saving to an object, adding to it piece by piece).
Here's what this will look like in operation. Assume you want to create some data for something analogous to a "dangerous dyads" design for all non-directed dyad-years. Here's how you'd do it in `{peacesciencer}`, which is going to be lifted from the source R scripts for the user's guide. The first part of this code chunk will lean on core `{peacesciencer}` functionality whereas the other stuff is some post-processing and, as a bonus, some modeling.
```{r, cache=F, message=F, eval=T}
# library(tidyverse) # load this first for most/all things
# library(peacesciencer) # the package of interest
# library(stevemisc) # a dependency, but also used for standardizing variables for better interpretation
library(tictoc)tic()
create_dyadyears(directed = FALSE, mry = FALSE) %>%
filter_prd() %>%
add_gml_mids(keep = NULL) %>%
add_peace_years() %>%
add_nmc() %>%
add_democracy() %>%
add_cow_alliance() %>%
add_sdp_gdp() -> DataData %>%
mutate(landcontig = ifelse(conttype == 1, 1, 0)) %>%
mutate(cowmajdyad = ifelse(cowmaj1 == 1 | cowmaj2 == 1, 1, 0)) %>%
# Create estimate of militarization as milper/tpop
# Then make a weak-link
mutate(milit1 = milper1/tpop1,
milit2 = milper2/tpop2,
minmilit = ifelse(milit1 > milit2,
milit2, milit1)) %>%
# create CINC proportion (lower over higher)
mutate(cincprop = ifelse(cinc1 > cinc2,
cinc2/cinc1, cinc1/cinc2)) %>%
# create weak-link specification using Quick UDS data
mutate(mindemest = ifelse(xm_qudsest1 > xm_qudsest2,
xm_qudsest2, xm_qudsest1)) %>%
# Create "weak-link" measure of jointly advanced economies
mutate(minwbgdppc = ifelse(wbgdppc2011est1 > wbgdppc2011est2,
wbgdppc2011est2, wbgdppc2011est1)) -> Data# r2sd() is in {stevemisc}, a {peacesciencer} dependency.
# This is just for a more readable regression output.
Data %>%
mutate_at(vars("cincprop", "mindemest", "minwbgdppc", "minmilit"),
~r2sd(.)) -> Databroom::tidy(modDD <- glm(gmlmidonset ~ landcontig + cincprop + cowmajdyad + cow_defense +
mindemest + minwbgdppc + minmilit +
gmlmidspell + I(gmlmidspell^2) + I(gmlmidspell^3), data= Data,
family=binomial(link="logit")))
toc()```
Here is how you might do a standard civil conflict analysis using Gleditsch-Ward states and UCDP conflict data.
```{r, cache=F, message=F, eval=T}
tic()
create_stateyears(system = 'gw') %>%
filter(year %in% c(1946:2019)) %>%
add_ucdp_acd(type=c("intrastate"), only_wars = FALSE) %>%
add_peace_years() %>%
add_democracy() %>%
add_creg_fractionalization() %>%
add_sdp_gdp() %>%
add_rugged_terrain() -> Datacreate_stateyears(system = 'gw') %>%
filter(year %in% c(1946:2019)) %>%
add_ucdp_acd(type=c("intrastate"), only_wars = TRUE) %>%
add_peace_years() %>%
rename_at(vars(ucdpongoing:ucdpspell), ~paste0("war_", .)) %>%
left_join(Data, .) -> DataData %>%
arrange(gwcode, year) %>%
group_by(gwcode) %>%
mutate_at(vars("xm_qudsest", "wbgdppc2011est",
"wbpopest"), list(l1 = ~lag(., 1))) %>%
rename_at(vars(contains("_l1")),
~paste("l1", gsub("_l1", "", .), sep = "_") ) -> DatamodCW <- list()
broom::tidy(modCW$"All UCDP Conflicts" <- glm(ucdponset ~ l1_wbgdppc2011est + l1_wbpopest +
l1_xm_qudsest + I(l1_xm_qudsest^2) +
newlmtnest + ethfrac + relfrac +
ucdpspell + I(ucdpspell^2) + I(ucdpspell^3), data=subset(Data),
family = binomial(link="logit")))broom::tidy(modCW$"Wars Only" <- glm(war_ucdponset ~ l1_wbgdppc2011est + l1_wbpopest +
l1_xm_qudsest + I(l1_xm_qudsest^2) +
newlmtnest + ethfrac + relfrac +
war_ucdpspell + I(war_ucdpspell^2) + I(war_ucdpspell^3), data=subset(Data),
family = binomial(link="logit")))toc()
```# Citing What You Do in `{peacesciencer}`
You can (and should) cite what you do in `{peacesciencer}`. The package includes a data frame of a `BibTeX` file (`ps_bib`) and a function for finding and returning `BibTeX` entries that you can include in your projects. This is the `ps_cite()` function. The `ps_cite()` function takes a string and does a partial match for relevant keywords (as `KEYWORDS`) associated with entries in the `ps_bib` file. For example, you can (and should) cite the package itself.
```{r}
ps_cite("peacesciencer")
```You can see what are the relevant citations to consider using for the data returned by `add_democracy()`
```{r}
ps_cite("add_democracy()")
```You can also return partial matches to see what citations are associated with, say, alliance data in this package.
```{r}
ps_cite("alliance")
```This function might expand in complexity in future releases, but you can use it right now for finding appropriate citations. You an also scan the `ps_bib` data to see what is in there.
# Issues/Requests
`{peacesciencer}` is already more than capable to meet a wide variety of needs in the peace science community. Users are free to raise an issue on the project's Github if some feature is not performing as they think it should or if there are additions they would like to see.