Skip to content

Instantly share code, notes, and snippets.

View jayyonamine's full-sized avatar

Jay Yonamine jayyonamine

View GitHub Profile
@jayyonamine
jayyonamine / plot_partial.r
Created March 14, 2015 17:00
plot_partial.r
library('ggplot2')
library('randomForest')
set.seed(2014)
rf_predict<-function(rf_object, data){
if (rf_object$type=="classification"){
p <-predict(rf_object, data, type="prob")
p<-as.vector(p[,2])
} else {
p <-predict(rf_object, data)
@jayyonamine
jayyonamine / gist:5372422
Created April 12, 2013 14:31
District-month predictions of violence in Afghanistan
##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")
@jayyonamine
jayyonamine / gist:3801453
Created September 28, 2012 18:39
Calculating F-measure with Random Forest
#################################
##Programmer: James E. Yonamine
##Helpful edits: Peter Li
##Date: 9/2/2012
##Random Forest Alpha Cutoff Function
#################################
##load pacakges and data
library(foreign)
library(MASS)
@jayyonamine
jayyonamine / gist:3717855
Created September 13, 2012 21:33
an introduction to Stacking
#################################
##Programmer: James E. Yonamine
##Date: 9/12/2012
##Basic introduction to stacking
#################################
##load pacakges and data
library(foreign)
library(Zelig)
library(MASS)
@jayyonamine
jayyonamine / gist:3626711
Created September 4, 2012 21:24
lasso of multiple imputations
##########################
##r code for greed and grievance replication/extension file
##James E. Yonamine
##4/13/2012
##data from http://www.apsanet.org/content_29436.cfm
##code takes 20 minutes to run on a 2.3 ghz intel core i5 with 4gb ram
##########################
library(foreign)
library(ROCR)
@jayyonamine
jayyonamine / gist:3626704
Created September 4, 2012 21:24
out-of-sample Bootstrapped logit
##########################
##r code for greed and grievance replication/extension file
##James E. Yonamine (worked off of VJD's original code)
##2/14/2012
##data from http://www.apsanet.org/content_29436.cfm
##########################
#if you don't have the packages below, un-comment them out and install.
#install.packages("ROCR")
#install.packages("fields")