Skip to content

Instantly share code, notes, and snippets.

View swiftsam's full-sized avatar

Sam Swift swiftsam

View GitHub Profile
@swiftsam
swiftsam / cac_fig4.R
Last active December 1, 2017 04:27
ggplot code to reproduce figure 4 from https://doi.org/10.1287/mnsc.2016.2525
library(ggplot2)
library(data.table)
library(scales)
ct.binned <- overp.indiv.ct[, list(confidence = mean(MeanMaxFcast),
hit_rate = mean(HitRate),
ci_hit_rate = 1.96*sd(HitRate)/sqrt(.N),
count = .N),
by=c("bin,ct")]
@swiftsam
swiftsam / r_cache.R
Created May 6, 2016 15:57
function caching function for R
####~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
### Cache (memoization) utilities
###
### Purpose
### * Functions to save the output of time consuming functions to memory and
### return results quickly if we already have the answers
###
### Notes: Standard usage would go like this
### FunctionName <- function(){
### args <- c(as.list(environment()), list())
@swiftsam
swiftsam / remove_dup__packages.R
Created February 9, 2016 16:47
remove R packages installed in multiple libraries
user.libs <- row.names(installed.packages(lib.loc = .libPaths()[1]))
sys.libs <- row.names(installed.packages(lib.loc = .libPaths()[2]))
remove.packages(intersect(sys.libs,user.libs), lib=.libPaths()[2])
@swiftsam
swiftsam / ordinal_brier.R
Created August 4, 2014 16:11
ordinal brier scoring
###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
### calculates Brier Score for a single forecast on an Ordered IFP
### calculation based on definition in Appendix B of ACE_TE_Plan_OY1_v3.
### procedure reduces penalty to probability assigned to bins adjacent
### to the realized outcome
###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ScoreOrdered <- function(fcast.values,
correct.values,
scoring.fn){
# Step 1 – Take the original categories (A-B-C-D) and break them up