Skip to content

Instantly share code, notes, and snippets.

View briatte's full-sized avatar

François Briatte briatte

View GitHub Profile
@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",
@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
@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,
@dsparks
dsparks / Visually-weighted regression.R
Created September 12, 2012 19:52
Visually-weighted regression plot, including simulation from a model
# A simple approach to visually-weighted regression plots
doInstall <- TRUE # Change to FALSE if you don't want packages installed.
toInstall <- c("ggplot2", "reshape2", "MASS")
if(doInstall){install.packages(toInstall, repos = "http://cran.us.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
# Generate some data:
nn <- 1000
myData <- data.frame(X = rnorm(nn),
@dsparks
dsparks / Making k-folds.R
Created September 11, 2012 01:55
Random, equally-sized partitions
# Randomly allocating observations into groups, for, e.g. cross-validation
kk <- 10 # Number of partitions, as in "kk-fold cross-validation."
# Here is a data.frame full of good data:
nn <- 1003
myData <- data.frame(matrix(rnorm(nn * 3), ncol = 3))
colnames(myData) <- LETTERS[1:3]
# This does not work:
whichK <- sample(LETTERS[1:kk], nrow(myData), replace = T)
@VikParuchuri
VikParuchuri / sentiment_plot.R
Created June 18, 2012 16:12
Generate Sentiment Plot
term<-c("egypt","jordan","israel","saudi")
term_vec<-foreach(i=1:length(all_score_frames),.combine=rbind) %do%
{
score_row<-rep(0,length(term))
for(z in 1:length(score_row))
{
sel_score<-all_score_frames[[i]][all_score_frames[[i]]$term==term[z],"score"]
sel_score[is.na(sel_score)]<-0
if(length(sel_score)==0)
sel_score<-0
@theconektd
theconektd / github.css
Created April 30, 2012 02:11
Github Markdown CSS - for Markdown Editor Preview
body {
font-family: Helvetica, arial, sans-serif;
font-size: 14px;
line-height: 1.6;
padding-top: 10px;
padding-bottom: 10px;
background-color: white;
padding: 30px; }
body > *:first-child {
@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.
@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
@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')