Skip to content

Instantly share code, notes, and snippets.

View jrnold's full-sized avatar

Jeffrey Arnold jrnold

View GitHub Profile
@mrowl
mrowl / enum_int_type.py
Created January 19, 2011 17:31
This defines a new enum type using the sqlalchemy type decorator. Data is stored with the sqlalchemy SmallInteger type while strings are used with the model. Preferable to the varchar (too large) or native enum (pain on postgres).
import sqlalchemy as sa
class EnumIntType(sa.types.TypeDecorator):
impl = sa.types.SmallInteger
values = None
def __init__(self, values=None):
sa.types.TypeDecorator.__init__(self)
self.values = values
#####################
## R Benchmark 2.5 ##
#####################
# http://r.research.att.com/benchmarks/R-benchmark-25.R
# R Benchmark 2.5 (06/2008) [Simon Urbanek]
# version 2.5: scaled to get roughly 1s per test, R 2.7.0 @ 2.6GHz Mac Pro
# R Benchmark 2.4 (06/2008) [Simon Urbanek]
# version 2.4 adapted to more recent Matrix package
# R Benchmark 2.3 (21 April 2004)
# Warning: changes are not carefully checked yet!
@leeper
leeper / checkurls.R
Last active April 30, 2016 06:36
Check URLs in a document
# Check URLs in a document
## This code will extract URLs from a text document using regex,
## then execute an HTTP HEAD request on each and report whether
## the request failed, whether a redirect occurred, etc. It might
## be useful for cleaning up linkrot.
if (!require("httr")) {
install.packages("httr", repos = "http://cran.rstudio.com/")
}
@mattblackwell
mattblackwell / clinton-rust-belt.R
Last active January 1, 2017 09:39
Analysis of the shift from 2012 to 2016
group.mean <- function(x, group) {
out <- tapply(x, group, mean, na.rm = TRUE)
out[group]
}
data(state.fips, package = "maps")
state.fips <- unique(state.fips[,c("fips","abb")])
state.fips$abb <- as.character(state.fips$abb)
state.fips <- rbind(state.fips, c(2, "AK"))
state.fips <- rbind(state.fips, c(15, "HI"))
# metadata
data_source <- "https://docs.google.com/spreadsheets/d/1xa0iLqYKz8x9Yc_rfhtmSOJQ2EGgeUVjvV4A8LsIaxY/htmlview?sle=true#gid=0"
data_collectors <- "Jeremy Pressman (@djpressman, U of Connecticut) and\nErica Chenoweth (@EricaChenoweth, U of Denver)"
code_gist <- "https://gist.github.com/benmarwick/a1ac9c7235ebef542824512162ff2f44"
# ------------------------------------------------------------------------
# read in data from google sheets to get a data frame

Horizons in Probabilistic Programming and Bayesian Analysis

Representations:

  • Hierarchical models
  • Hidden Markov models
  • Graphical models
  • Non-parametric Bayes (distributions over functions)

Inference Approaches:

@rage-shadowman
rage-shadowman / git-svn-diff.sh
Last active August 28, 2017 10:02 — forked from markjaquith/git-svn-diff.sh
fixed bug with diff of newly added files
#!/bin/bash
#
# git-svn-diff originally by (http://mojodna.net/2009/02/24/my-work-git-workflow.html)
# modified by mike@mikepearce.net
# modified by aconway@[redacted] - handle diffs that introduce new files
# modified by t.broyer@ltgt.net - fixes diffs that introduce new files
# modified by m@rkj.me - fix sed syntax issue in OS X
# modified by rage-shadowman - cleaned up finding of SVN info and handling of path parameters
# modified by tianyapiaozi - cleaned up some diff context lines
#
@carlislerainey
carlislerainey / probit-product-term.R
Created December 1, 2017 23:05
code to understand product terms and probit models
# code to understand product terms and probit models
# clear workspace
rm(list = ls())
# load packages
library(tidyverse)
library(plotly)
# parameters
@xflr6
xflr6 / glottolog.ipynb
Last active December 17, 2018 20:34
Glottolog with Python
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mbjoseph
mbjoseph / leung_drton_factor_analysis.R
Last active January 16, 2020 08:56
Factor analysis sandbox
# Simulation script for factor analysis ala Leung & Drton (2016) ----------
library(rstan)
library(bayesplot)
m <- 5 # dimension of observed data (e.g., # traits)
k <- 2 # number of latent factors
n <- 100 # number of sample units (e.g., # species)
# residual variance matrix (is diagonal)
Omega <- diag(.3 + abs(rnorm(m, sd = .3)))