Skip to content

Instantly share code, notes, and snippets.

View jrnold's full-sized avatar

Jeffrey Arnold jrnold

View GitHub Profile
@jrnold
jrnold / stan.snippets
Created July 22, 2015 16:06
Snippets for Stan in ACE / Rstudio
snippet for
for (${1:var} in ${2:start}:${3:end}) {
${0}
}
snippet if
if (${1:condition}) {
${0}
}
@jrnold
jrnold / eng_printfile.R
Last active August 29, 2015 14:25
Knitr engine for printing a file
eng_printfile <- function(options) {
code <- paste(readLines(options$engine.opts$file), collapse = "\n")
options$engine <- options$engine.opts$lang
knitr::engine_output(options, code, '')
}
knitr::knit_engines$set(printfile = eng_printfile)
@jrnold
jrnold / whatever.R
Created May 30, 2015 17:26
Using a list as an environment in R
list_of_stuff <-
list(a = rnorm(100),
b = rnorm(100))
with(list_of_stuff, plot(a, b))
@jrnold
jrnold / csss_221_install.R
Created January 8, 2015 02:00
CS&SS/SOC/STAT 221 Install script
#' CS&SS/SOC/STAT 221 Install Script
#'
#' Install R Commander and necessary packages and data to be
#' used in CS&SS/SOC/STAT 221.
#'
is_installed <- function(pkg) {
is.element(pkg, installed.packages()[,1])
}
intall.packages("devtools")
devtools::install_github(c("jrnold/bps5data", "jrnold/bps6data"))
@jrnold
jrnold / gist:c4867ddf82b2913803d2
Last active February 19, 2017 21:07
Treebank word tokenizer in R
# Treebank Tokenizer in R
#
# Code is a port of the NLTK python and sed scripts:
# - http://www.nltk.org/_modules/nltk/tokenize/treebank.html#TreebankWordTokenizer
# - http://www.cis.upenn.edu/~treebank/tokenizer.sed
library("stringr")
library("tokenizers")
library("microbenchmark")
.CONTRACTIONS2 <-
@jrnold
jrnold / locallevel.stan
Created October 1, 2014 15:46
local level model in Stan reparameterized using Matt's trick
// Local Level model in Stan
// parameterized using Matt's Trick
data {
int n;
vector[n] y;
real<lower=0> theta1_mean;
real<lower=0> theta1_sd;
}
parameters {
real<lower=0> sigma_v;
@jrnold
jrnold / example.stan
Last active August 29, 2015 14:03
Stan syntax example file
/*
A file for testing Stan syntax highlighting.
It is not a real model and will not compile
*/
# also a comment
// also a comment
functions {
void f1(void a, real b) {
return 1 / a;
@jrnold
jrnold / stanmode.js
Created June 29, 2014 13:33
ACE editor mode for Stan
define(function(require, exports, module) {
var oop = require("../lib/oop");
var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
var StanHighlightRules = function() {
var keywords = (