Skip to content

Instantly share code, notes, and snippets.

View jrnold's full-sized avatar

Jeffrey Arnold jrnold

View GitHub Profile
@jrnold
jrnold / gist:9f21e4862a997294b245
Created May 5, 2014 23:54
Don't use periods for variable names in R
foo <- structure(rnorm(100), class = "test")
t(foo)
data {
int jj_n;
int jj_idx[jj_n];
int jj_groups[jj_n];
...
}
parameters {
vector[3] beta;
...
}
@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 / 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;
intall.packages("devtools")
devtools::install_github(c("jrnold/bps5data", "jrnold/bps6data"))
@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])
}
@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 / 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 / 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}
}