Skip to content

Instantly share code, notes, and snippets.

View briatte's full-sized avatar

François Briatte briatte

View GitHub Profile
@briatte
briatte / imf.R
Last active January 22, 2016 08:10 — forked from chrishanretty/imf.R
remixing Chris Giles' analysis of IMF WEO, threading on Chris Hanretty's R code
# Chris Giles:
#
# "Robustness of IMF data scrutinised", Oct 12 2012:
# http://www.ft.com/intl/cms/s/0/85a0c6c2-1476-11e2-8cf2-00144feabdc0.html#axzz2LKQkV3SH
#
# "Has the IMF proved multipliers are really large? (wonkish)" Oct 12 2012:
# http://blogs.ft.com/money-supply/2012/10/12/has-the-imf-proved-multipliers-are-really-large-wonkish/
#
# "The IMF and multipliers, again", Jan 7 2013:
# http://blogs.ft.com/money-supply/2013/01/07/the-imf-and-multipliers-again/
##programmer: JEY
##2/28/2013
##District-month forecasts
##note: this takes about 5 minutes to run. It throws lots of errors due to many all zero time series, but it will eventually complete and build predictions
rm(list=ls())
library(foreign)
library(forecast)
library(sos)
data<-read.dta("raw_AFG.dta")
### Takes as input a Google Docs spreadsheet
### Outputs national and regional level estimates of support
### over time
### Load libraries
library(R2WinBUGS)
library(rjags)
library(RCurl)
library(reshape)
library(foreach)
## 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)
@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")
@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 / 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")
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 / 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)
@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, ilya.kashnitsky@gmail.com
#
################################################################################
# Erase all objects in memory
rm(list = ls(all = TRUE))