This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Replicate | |
### | |
### Kim, Nam Kyu. "Previous Military Rule and Democratic Survival." Journal of Conflict Resolution 65, no. 2-3 (2021): 534-562 | |
### | |
### including an additional covariate for a hereditary head of state | |
### | |
library(rio) | |
library(tidyverse) | |
library(vdemdata) | |
library(countrycode) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(rio) | |
library(hrbrthemes) | |
### (1) Get files in | |
### Parish to Ward | |
### https://geoportal.statistics.gov.uk/datasets/ons::parish-to-ward-to-local-authority-district-december-2020-lookup-in-england-and-wales-v2/about | |
par2ward <- read.csv("Parish_to_Ward_to_Local_Authority_District__December_2020__Lookup_in_England_and_Wales_V2.csv") | |
par2ward$FID <- NULL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(cmdstanr) | |
library(MCMCpack) | |
### log PDF is based on eqn. 3 in https://www2.seas.gwu.edu/~dorpjr/Publications/Bookchapter/MarcelDekker2003.pdf | |
stan_code <- | |
" | |
functions { | |
real orddir_lpdf(vector y, real[] alpha) { | |
int K = size(alpha); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
library(reshape2) | |
library(nnet) | |
library(multinomRob) | |
library(VGAM) | |
#type <- "nnet" | |
type <- "vgam" | |
sim.multinom <- function(object = mod, newdata = NULL, nSims = 10) { | |
### Some of this code is hacked from the internals of |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(countrycode) | |
library(tidyverse) | |
library(rio) | |
holder <- list() | |
### (0) PartyFacts lookup | |
pf <- read.csv("data/partyfacts-external-parties.csv") | |
### (1) Manifesto Project |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Let's generate some data with a step function | |
library(mgcv) | |
set.seed(1116) | |
nDays <- 200 | |
day <- 1:nDays | |
y <- rnorm(200, 1, 0.25) + I(day > 100) * -0.5 | |
y <- ifelse(y < 0, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(sp) | |
library(raster) | |
library(viridis) | |
library(rgdal) | |
library(rnaturalearth) | |
### need two things, presumably | |
### - a polygon mask | |
### - a population raster |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
### Pivot the table so we have four columns | |
### L/R, GAL/TAN, issue area, and value | |
dat <- read.csv("surridge1.csv") %>% | |
pivot_longer(cols = -c(Column1, Column2), | |
names_to = "Area") | |
### Tidy up the factor levels and order | |
dat <- dat %>% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(brms) | |
library(mice) | |
library(tictoc) | |
### Set a nice long number of iters so we can be sure it's not the | |
### overhead of spinning up cores, passing data, etc., | |
nIters <- 1e5 | |
thin <- nIters / 1000 | |
# Load data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Generate a plot which shows the changing length of constitutions over time | |
### The plot uses data from the Comparative Constitutions Project | |
## Load libraries | |
library(tidyverse) | |
library(hrbrthemes) | |
## Set this to true and amend file_locn if you have the data | |
beast_mode <- FALSE | |
if (beast_mode) { |