Skip to content

Instantly share code, notes, and snippets.

View briatte's full-sized avatar

François Briatte briatte

View GitHub Profile
@ptoche
ptoche / ps-income-shares.csv
Last active August 29, 2015 14:00
Piketty & Saez, Top Incomes in the U.S., 1913-2012
Year Fractile value
1 1913-01-01 Top 0.01% 0.0275501620545077
2 1914-01-01 Top 0.01% 0.0272920847365446
3 1915-01-01 Top 0.01% 0.0436035
4 1916-01-01 Top 0.01% 0.0440493410443468
5 1917-01-01 Top 0.01% 0.0333076913805183
6 1918-01-01 Top 0.01% 0.0244816293043196
7 1919-01-01 Top 0.01% 0.0222020659211262
8 1920-01-01 Top 0.01% 0.0167163862642264
9 1921-01-01 Top 0.01% 0.0168921038823408
@tslumley
tslumley / moe
Created August 21, 2014 23:53
Margin of error in polls, based on actual percentage and allowing for design effects
moe = function(pct, N=1000, deff=c(1,2)){
p.L = function(x, n) {
ifelse (x == 0,0,qbeta(0.025, x, n - x + 1))
}
p.U = function(x, n) {
ifelse(x == n,1,qbeta(0.975, x + 1, n - x))
}
N = rep(N,length(pct))
lower = function(pct,deff){
a1 <- c(4.2,3.2,11.1,1.3,2.2,2.0)
a2 <- c(3.9,3.2,10.0,0.8,3.1,3.1)
a3 <- c(6.3,2.5,9.8,0.9,2.2,2.4)
a4 <- c(4.4,3.1,9.8,0.8,3.3,2.7)
a5 <- c(4.8,3.0,9.9,0.7,3.3,2.4)
a6 <- c(4.0,3.4,10.5,0.7,3.3,2.1)
a <- rbind(a1,a2,a3,a4,a5,a6)
# Get data into tidy format, starting with a, defined above
@jbryer
jbryer / RBloggers.R
Created January 13, 2012 15:14
Retrieving and Analyzing R-Bloggers using the Google Reader API
source('https://raw.github.com/gist/1606595/269d61dfcc7930f5275a212e11f3c43771ab2591/GoogleReader.R')
rbloggers = getRSSFeed(feedURL="http://r-bloggers.com/feed",
email="GOOGLE READER EMAIL",
passwd="GOOGLE READER PASSWORD",
posts=5000)
entries = rbloggers[which(names(rbloggers) == "entry")]
length(entries)
saveXML(rbloggers, file='rbloggers.xml')
@thomasjensen
thomasjensen / textmining.r
Created January 26, 2012 14:40
text mining of Politikken
##read in the libraries and set the working directory
library(tm)
library(corrplot)
setwd("/path/to/")
##read in the data and subset it to the relevant categories
data <- read.csv("indvandringPolitikken.csv", fileEncoding = "latin1")
data <- data[data$kategori == "Politik" | data$kategori == "Debat" | data$kategori == "Kronikken" | data$kategori == "Leder", ]
##create the corpus and clean it
@alexstorer
alexstorer / plotDecision.m
Created April 12, 2012 17:32
Plot the distributions of two gaussians along with a criterion, in the style of decision theory.
function h = plotDecision(dprime,sdnoise,criterion)
% h = plotDecision(dprime, sdnoise, criterion)
%
% plotDecision makes a plot of two Gaussian functions, inspired by signal
% detection theory. The inputs are given in terms of standard deviates of
% the signal distribution:
%
% dprime - d', the distance between the means of the Gaussians
% sdnoise - $\sigma$, the ratio of the standard deviation of the noise to
% the standard deviation of the signal.
@cdesante
cdesante / dummy probit.r
Created September 14, 2012 19:19
Probit with indicator variable
###### Ordered Categorical DV: #####
#This uses "importance of aid to blacks" as a DV and race of R as the indicator IV.#
library(MASS)
white <- c(1,1,0,1,1,1,1,0,1,1,1,0,1,1,1,1,1,0,1,1,1,1,0,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,
1,1,0,1,1,1,1,1,1,1,1,1,0,0,0,1,0,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,0,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,0,1,0,1,0,1,1,1,1,0,1,0,0,1,0,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,1,0,
1,1,1,1,1,1,1,1,1,1,0,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,0,1,0,1,1,1,0,0,1,1,1,1,1,1,1,0,1,0,0,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,0,1,1,1,
0,1,1,0,1,1,1,1,1,1,0,0,1,1,0,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,0,1,0,1,0,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,0,1,
1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,
@christophergandrud
christophergandrud / relativeNPLGraph.R
Created October 4, 2012 04:28
Relative Non-proportional Hazard Graph in R
#################
# Use R to recreate part of QMV the relative non-proportional hazard estimation graph (fig 2) from Licht (2011)
# Christopher Gandrud (http://christophergandrud.blogspot.com/)
# 4 October 2012
#################
#### Set Up ####
# Load required libraries
@chrishanretty
chrishanretty / imf.R
Created October 13, 2012 18:42
Replicates Chris Giles' analysis of IMF WEO
library(gdata)
library(countrycode)
infile <- "IMFmultipliers.xls"
imf_rep <- read.xls(infile, sheet = 2,
skip = 3,
header=F)
names(imf_rep) <- c("Country",
"gdp_4cast_2011","gdp_4cast_2012",
@chrishanretty
chrishanretty / cogsd7.R
Created November 20, 2012 14:26
Create replacement risk using ParlGov data
library(plyr)
library(zoo)
startyr <- 1992
endyr <- 2012
pg <- read.csv("http://www.parlgov.org/stable/static/data/stable-utf-8/view_cabinet.csv",as.is=T)
## Exclude GDR
pg <- pg[which(pg$country_name_short!="GDR"),]