Skip to content

Instantly share code, notes, and snippets.

View briatte's full-sized avatar

François Briatte briatte

View GitHub Profile
@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",
@mbostock
mbostock / .block
Last active November 21, 2023 20:22 — forked from mbostock/.block
Choropleth
license: gpl-3.0
height: 600
border: no
redirect: https://beta.observablehq.com/@mbostock/d3-choropleth
@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"),]
@dsparks
dsparks / tapered-intensity-curved_edges.R
Last active December 8, 2021 12:23
Beautiful tapered-intensity-curved edge network graph with ggplot2
doInstall <- TRUE # Change to FALSE if you don't want packages installed.
toInstall <- c("sna", "ggplot2", "Hmisc", "reshape2")
if(doInstall){install.packages(toInstall, repos = "http://cran.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
# Empty ggplot2 theme
new_theme_empty <- theme_bw()
new_theme_empty$line <- element_blank()
new_theme_empty$rect <- element_blank()
new_theme_empty$strip.text <- element_blank()
@dsparks
dsparks / latent_class_analysis.R
Created December 19, 2012 16:24
Latent class model of ANES respondents
doInstall <- TRUE
toInstall <- c("ggplot2", "poLCA", "reshape2")
if(doInstall){install.packages(toInstall, repos = "http://cran.us.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
ANES <- read.csv("http://www.oberlin.edu/faculty/cdesante/assets/downloads/ANES.csv")
ANES <- ANES[ANES$year == 2008, -c(1, 11, 17)] # Limit to just 2008 respondents,
head(ANES) # remove some non-helpful variables
# Adjust so that 1 is the minimum value for each variable:
ANES <- data.frame(apply(ANES, 2, function(cc){ cc - min(cc, na.rm = T) + 1 }))
@jbryer
jbryer / parse.codebook.r
Last active March 9, 2023 15:19
Parses a codebook file where lines starting at column zero (far left) represet variable information (e.g. name, description, type) and indented lines (i.e. lines beginning with white space, either tabs or spaces, etc.) represent factor levels and labels.
#' Parse a codebook file with variable and level information.
#'
#' Parses a codebook file where lines starting at column zero (far left) represet
#' variable information (e.g. name, description, type) and indented lines
#' (i.e. lines beginning with white space, either tabs or spaces, etc.) represent factor
#' levels and labels.
#'
#' Note that white space at the beginning and end of each line is stripped before
#' processing that line.
#'
@chrishanretty
chrishanretty / pooling_spe.R
Created February 10, 2013 18:21
Pooling the polls for Italy, final version
### 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)
@xmarquez
xmarquez / List-of-variables-ccp.csv
Last active December 12, 2015 09:39
Code for post on the Normativeness of Democracy
variable Question
cowcode Correlates of War country code (www.correlatesofwar.org).
country Country name.
systyear Year in which the constitutional system was promulgated.
systid Unique identification number for the constitutional system.
evntyear Year of promulgation of the most recent constitutional event.
endyear Year through which the data for the event is guaranteed valid.
evntid Unique identification number for the constitutional event.
evnttype Event type (e.g. amendment, new, etc.).
source What is the source for the text of the Constitution?