This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
read.qualtrics.csv <- function(filename, stringsAsFactors = FALSE, ...) { | |
n <- read.csv(filename, nrows = 1, stringsAsFactors = FALSE) | |
dat <- read.csv(filename, header = FALSE, skip = 2, stringsAsFactors = stringsAsFactors, ...) | |
names(dat) <- names(n) | |
names(dat)[1:10] <- n[1,1:10] | |
for(i in seq_along(dat)) { | |
attr(dat[,i], "question") <- n[1,i] | |
} | |
dat | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
install: | |
- sudo apt-get install texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended | |
- sudo apt-get install chktex | |
script: | |
- make | |
- chktex -W # Print version information. | |
- chktex -q -n 6 *.tex chapters.*.tex 2>/dev/null | tee lint.out | |
# If lint output is non-empty report an error. | |
- test ! -s lint.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#plot.stream makes a "stream plot" where each y series is plotted | |
#as stacked filled polygons on alternating sides of a baseline. | |
# | |
#Arguments include: | |
#'x' - a vector of values | |
#'y' - a matrix of data series (columns) corresponding to x | |
#'order.method' = c("as.is", "max", "first") | |
# "as.is" - plot in order of y column | |
# "max" - plot in order of when each y series reaches maximum value | |
# "first" - plot in order of when each y series first value > 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stratified <- function(df, group, size, select = NULL, | |
replace = FALSE, bothSets = FALSE) { | |
if (is.null(select)) { | |
df <- df | |
} else { | |
if (is.null(names(select))) stop("'select' must be a named list") | |
if (!all(names(select) %in% names(df))) | |
stop("Please verify your 'select' argument") | |
temp <- sapply(names(select), | |
function(x) df[[x]] %in% select[[x]]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Usage: phantomjs screenshot.js 1920x1080 site.domain.com | |
// outputs to site.domain.com-1920x1080.png | |
// dont add http to the URL | |
// If the page didnt render in time add a delay argument | |
// e.g. 3000 for 3 seconds | |
var page = require('webpage').create(); | |
var args = require('system').args; | |
var wh = args[1].split('x'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' 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. | |
#' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(segue) | |
setCredentials(getOption("amazon_key"), getOption("amazon_secret")) | |
require(mcmcTools) | |
X <- rnorm(20, 2, 5) | |
loglik <- function(pars){ | |
sum( dnorm(X, mean=pars[1], sd=pars[2], log=TRUE) ) | |
} | |
prior <- function(pars){ | |
1/pars[2]^2 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/Rscript | |
library(twitteR) | |
library(imguR) | |
sess <- initSession("clark_lab_linux", "password") | |
rstats <- searchTwitter("#rstats", sess, n=1000) | |
#filter out junk | |
rstats <- rstats[sapply(sapply(rstats, screenName), length)>0] | |
#make graph | |
posters <- sort(table(sapply(rstats, screenName)), decreasing=TRUE) |
NewerOlder