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
# Log in to event database first, e.g. | |
# mysql -u xxx -p -h IPaddress -D event_data | |
SET @countryid = (SELECT id FROM countries WHERE countryname='CYPRUS'); | |
# Pull events and related information, takes 1.5m for Cyprus, and save | |
# to a csv file | |
CREATE TABLE temp_results AS | |
SELECT e.event_ID, | |
e.event_date, |
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
worldMap <- function(x, id, data, date='2008-01-01', legend.title=NULL, | |
maxy=1) { | |
# Input 2-column matrix with unique identifier and data to be mapped for | |
# state slice in "date", output thematic map. | |
require(cshapes) | |
require(maptools) | |
require(RColorBrewer) # for color palettes | |
require(plyr) | |
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
# Change to your data | |
data <- data.frame(resp=1:5, | |
w11=sample(1:5, 5, replace=TRUE), | |
w12=sample(1:5, 5, replace=TRUE), | |
w13=sample(1:5, 5, replace=TRUE)) | |
data$LoySum <- apply(data[, c("w11", "w12", "w13")], 1, mean) | |
# Names of the variables we want to look at | |
q.names <- c("w11", "w12", "w13") |
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
setwd("/Volumes/political-science/shared/ICEWS Project/C-IED/Data/Global_WITS") | |
# Read as txt chunk | |
# The first 16 lines are meta data | |
wits.text <- readLines("WITS.csv") | |
head(wits.text, n=16) | |
# Get actual data | |
wits <- read.csv(text=wits.text, header=TRUE, skip=16) |
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
# from here http://blog.55minutes.com/2013/09/postgresql-93-brew-upgrade/ | |
# Create backup of database | |
/usr/local/cellar/postgresql/9.2.4/bin/pg_dump -h localhost -p 5432 -U ab428 -Fc -b -v -f "/usr/local/var/pg_backup/afghanistan.backup" afghanistan | |
# Upgrade PostGIS | |
brew doctor # fix errors | |
brew update | |
brew upgrade postgres | |
brew upgrade gdal --with-postgres |
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
## Correlations for blog post | |
library(plyr) | |
# from GT | |
# source directories and first few lines of pull-data.R | |
sql <- | |
"SELECT dateoccured AS date, count(*) AS sigacts | |
FROM sigacts |
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
# Archigos transitions and tenure by regime type | |
# | |
# Andreas Beger | |
# 15 December 2014 | |
setwd("~/Desktop/archigos-polity") | |
library(foreign) | |
library(gdata) |
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
# EBMA ensemble prediction | |
# | |
# Aggregate a set of predictions into an ensemble prediction using a fitted | |
# EBMA model. Recreates the functionality used to calculate test predictions | |
# during a EBMA calibration call. | |
# | |
# ebma - A fitted EBMA object; only works with logit EBMA. | |
# inputs - Matrix or data frame in which each column is a series of | |
# probabilities. | |
# outcome - Vector of observed outcomes. Lenght must match rows in inputs. |
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
# Dot density map | |
# Eventually should be like http://www.radicalcartography.net/index.html?frenchkisses | |
library(maptools) | |
nc_SP <- readShapePoly(system.file("shapes/sids.shp", package="maptools")[1], | |
proj4string=CRS("+proj=longlat +ellps=clrk66")) | |
## Not run: | |
pls <- slot(nc_SP, "polygons") |
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("ggplot2") | |
df <- structure(list(date = structure(c(17532, 17897, 18262, 18993, | |
19358, 19723, 20089), class = "Date"), id = c("9991", "9991", | |
"9991", "9992", "9992", "9992", "9992"), cowcode = c(999, 999, | |
999, 999, 999, 999, 999), y = c(1, 1, 1, 2, 2, 2, 2)), row.names = c(NA, | |
-7L), class = "data.frame") | |
ggplot(df, aes(x = date, y = y, group = cowcode)) + geom_line() |