Skip to content

Instantly share code, notes, and snippets.

View briatte's full-sized avatar

François Briatte briatte

View GitHub Profile
@briatte
briatte / crayola.R
Last active December 18, 2015 16:49
Crayola color vector for R
crayola <- structure(c("#EFDECD", "#CD9575", "#FDD9B5", "#78DBE2", "#87A96B",
"#FFA474", "#FAE7B5", "#9F8170", "#FD7C6E", "#000000", "#ACE5EE",
"#1F75FE", "#A2A2D0", "#6699CC", "#0D98BA", "#7366BD", "#DE5D83",
"#CB4154", "#B4674D", "#FF7F49", "#EA7E5D", "#B0B7C6", "#FFFF99",
"#1CD3A2", "#FFAACC", "#DD4492", "#1DACD6", "#BC5D58", "#DD9475",
"#9ACEEB", "#FFBCD9", "#FDDB6D", "#2B6CC4", "#EFCDB8", "#6E5160",
"#CEFF1D", "#71BC78", "#6DAE81", "#C364C5", "#CC6666", "#E7C697",
"#FCD975", "#A8E4A0", "#95918C", "#1CAC78", "#1164B4", "#F0E891",
"#FF1DCE", "#B2EC5D", "#5D76CB", "#CA3767", "#3BB08F", "#FEFE22",
"#FCB4D5", "#FFF44F", "#FFBD88", "#F664AF", "#AAF0D1", "#CD4A4C",
@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 / pj.bipartite.R
Last active December 19, 2015 15:18
Pedro Jordano's method to plot bipartite networks with ggnet
require(downloader)
# PJ example.
link = "https://raw.github.com/pedroj/bipartite_plots/master/data/NCH_quant_bmatrix.txt"
file = "data/NCH_quant_bmatrix.txt"
if(!file.exists(file)) download(link, file, mode = "wb")
M <- read.table(file, sep = "\t", dec = ",", header = TRUE, row.names = 1)
#
# Bipartite network initialization, starting from an adjacency matrix.
> # Get data for 2011
> query <- c("cbt" = "'cognitive behavior therapy' OR 'cognitive behavioral therapy' OR 'cognitive therapy' AND 2011[DP]")
> pub.efetch <- searchPubmed(query)
Searching (downloading 1718 articles)
Completed download from PubMed.
> cbt_2011 <- extractJournal()
XML declaration allowed only at the start of the document
StartTag: invalid element name
Error: 1: XML declaration allowed only at the start of the document
2: StartTag: invalid element name
@briatte
briatte / README.md
Last active December 20, 2015 00:39
Visually weighted quantile regressions. Initial code by Martin Johnsson.
@briatte
briatte / google.css
Created July 20, 2013 15:16
discrete colour palette used in Google Ngram, Google Trends and probably elsewhere (12 classes)
a { color: #264EC0; }
b { color: #D22310; }
c { color: #FC8608; }
d { color: #168713; }
e { color: #850086; }
f { color: #1086B9; }
g { color: #D22B63; }
h { color: #559D05; }
i { color: #A71B23; }
j { color: #21436F; }
@briatte
briatte / 00_survey_data_README.md
Last active January 2, 2019 02:45
A few snippets to quickly get a selection of social science datasets into R.

Here are little chunks of R code to quickly access survey datasets. Some of the linked datasets are provided on an "as-is" basis: typically, you might want to check the official ANES files rather than rely on the extracts linked to below. This also applies to data extracts bundled in packages.

HOWTO

The code occasionally calls the download and foreign packages, respectively to get files from HTTPS sources and to deal with foreign formats. The Gelman and Hill replication also uses plyr and ggplot2, but check the original code for identical functions written in base R.

SEEALSO

@briatte
briatte / 0.README.md
Last active December 20, 2015 12:39
extract variable labels from QOG data, save as R data frames

This Gist is used to create the variable indexes in this package:

  1. Stata do-file to extract the variable labels
  2. R script to convert the files to R data frames.
  3. R script to create the demo datasets.

The scripts all worked in early August 2013.

Exceptions corrected by the do-file:

@briatte
briatte / demo.log
Last active December 21, 2015 05:29
Stata log of the entire SRQM course, produced with -srqm_demo using demo.log, s(1/12) test wipe- on August 17, 2013.
------------------------------------------------------------------------------------
name: srqm_demo
log: /Users/fr/Documents/Teaching/SRQM/demo.log
log type: text
opened on: 17 Aug 2013, 18:28:28
.
. * Check setup. This line appears in every course do-file. It makes sure that
. * you have the appropriate files and packages to successfully run the code.
. run setup/require fre lookfor_all
@briatte
briatte / LIS.README.md
Last active December 22, 2015 01:48
Use Quandl to download country-year observations from the Luxembourg Income Study.

You will need to insert your authentification token where the code says [TOKEN].

The data availability ranges from null to full in function of the country of interest:

Here's a quick plot of the 90/10 percentile ratio for European countries: