Skip to content

Instantly share code, notes, and snippets.

View briatte's full-sized avatar

François Briatte briatte

View GitHub Profile
@briatte
briatte / terrorism-in-ukg-1970-2015.R
Created August 23, 2017 14:16 — forked from svmiller/terrorism-in-ukg-1970-2015.R
Model terrorism patterns in the United Kingdom
# You won't need all of these packages. I just copied it from another,related analysis:
# https://github.com/svmiller/etjc
library(car)
library(arm)
library(countrycode)
library(data.table)
library(tidyverse)
library(sqldf)
# library(pdftools)
@briatte
briatte / vpt.R
Created August 2, 2017 08:26 — forked from chrishanretty/vpt.R
Replicating Angelova et al., "Veto player theory and reform making in Western Europe"
library(MASS)
library(rio)
library(tidyverse)
multhet <- function(y, ## = formula(1~1),
v, ## = formula(~1),
data) {
## check length of inputs
if (class(y) != "formula") {
@briatte
briatte / NEET-in-Europe.R
Created July 19, 2017 16:40 — forked from ikashnitsky/NEET-in-Europe.R
Young people neither in employment nor in education and training in Europe, 2000-2016
################################################################################
#
# ikashnitsky.github.io 2017-07-18
# Accessing Eurostat data using the `eurostat` R package
# Young people neither in employment nor in education and training in Europe
# Ilya Kashnitsky, [email protected]
#
################################################################################
# Erase all objects in memory
@briatte
briatte / colorcoded-map-population-structures.R
Created July 3, 2017 15:07 — forked from ikashnitsky/colorcoded-map-population-structures.R
Code to reproduce the RGB map of the population structure of NUTS-3 regions of Europe -- https://ikashnitsky.github.io/2017/colorcoded-map/
################################################################################
#
# ikashnitsky.github.io 2017-06-30
# Produce an RGB coded map of pop structures at NUTS-3 level
# Ilya Kashnitsky, [email protected]
#
################################################################################
# Erase all objects in memory
rm(list = ls(all = TRUE))
@briatte
briatte / minority_report.R
Created June 20, 2017 21:16 — forked from chrishanretty/minority_report.R
Get stats on minority government from ParlGov
library(tidyverse)
### Make sure to download files from www.parlgov.org!
elec <- read.csv("view_election.csv")
cab <- read.csv("view_cabinet.csv")
party <- read.csv("view_party.csv")
### Date
cab$start_date <- as.Date(cab$start_date)
library(httr)
adresse <- "8 bd du port"
resultraw <- httr::GET(utils::URLencode(paste0('https://api-adresse.data.gouv.fr/search/?q=', adresse)))
result <-jsonlite::fromJSON(httr::content(resultraw, "text"))
result$features
@briatte
briatte / conswing.R
Created April 24, 2017 20:45 — forked from chrishanretty/conswing.R
Analysis of swings in Conservative and Labour-held seats, BES data
library(foreign) ## for data import
library(dplyr) ## for chaining ops together
library(ggplot2) ## for plotting
library(reshape2) ## for reshaping
library(hrbrthemes) ## for pretty pictures
library(survey) ## for... uh, survey data
party.colours <- c("#0087DC","#D50000","#FDBB30","#FFFF00","#008142","#99CC33","#70147A","#DDDDDD")
bes <- read.spss("~/Dropbox/2017-forecasting/data/individual/BES2015_W10_Panel_v0.3.sav")
@briatte
briatte / brexit.R
Last active December 12, 2016 13:24 — forked from rCarto/brexit.R
code by Arthur Charpentier and Timothée Giraud to plot a map of the 'Brexit' vote results -- see sources in the comments
library(sp)
library(raster)
library(rgeos)
## import des données
download.file(url = "http://biogeo.ucdavis.edu/data/gadm2.8/rds/GBR_adm2.rds",
destfile = file.path(tempdir(), "GBR_adm2.rds"))
download.file(url = "http://biogeo.ucdavis.edu/data/gadm2.8/rds/IRL_adm0.rds",
file.path(tempdir(),"IRL_adm0.rds"))
@briatte
briatte / boot.ci.r
Last active December 18, 2015 21:39 — forked from dmarcelinobr/myboot.R
Daniel Marcelino's bootstrap function for regression coefficients, made parallelizable + bootstrapped CIs
library(boot)
r2 = function(f, d, i) {
d = d[i, ]
f = lm(f, data = d)
return(summary(f)$r.square)
}
br <- boot(COI, r2, 10000, formula = nb.publis ~ nb.liens)
br
plot(br)
boot.ci(br, .95, "bca")
## Please note, this script is entirely derivative of work done
## by Simon Jackman for his article `Pooling the Polls...'
## Aust. J. Pol. Science, 40(4): 499-517
## Libraries
library(reshape)
library(rjags)
library(R2WinBUGS)
library(ggplot2)
library(scales)