Skip to content

Instantly share code, notes, and snippets.

View floswald's full-sized avatar
👋

Florian Oswald floswald

👋
View GitHub Profile
@floswald
floswald / util.r
Created January 25, 2012 17:13
utility function
####################################
# R code for a CRRA Utility function
# Florian Oswald
# u(c) is defined over consumption c \in [-\infty,\infty]
# has automatic switch to log if CRRA = 1
# can produce diagnostic plot
# INPUT: x = vector of consumption values
# params = list with 3 entries: CRRA(numeric), cutoff(numeric), diag.plot(bool)
# e.g. utility.params <- list('CRRA' = CRRA, 'cutoff' = cutoff, diag.plot=FALSE)
# 'cutoff' is a number chosen by the user below which u(c) is quadratically approximated
@floswald
floswald / dda2.r
Created January 17, 2012 20:14
DDA code
# deferred acceptance algorithm after Gale and Shapley
# Deferred Acceptance Algorithm with male offer
# accepts your preferences or chooses randomly
daa <- function(nMen,nWomen,m.prefs=NULL,w.prefs=NULL){
require(animation) # load animation package
if (is.null(m.prefs)){ # if no prefs given, make them randomly
m.prefs <- replicate(n=nMen,sample(seq(from=1,to=nWomen,by=1)))
@floswald
floswald / DAA.r
Created January 15, 2012 21:21
DAA code
# deferred acceptance algorithm after Gale and Shapley
# coded by florian oswald
# [email protected]
# Deferred Acceptance Algorithm with male offer
# accepts your preferences or chooses randomly
# to test, use jan's example preferences:
# m.prefs = matrix(data=c(1,2,3,4,4,2,3,1,4,3,1,2,1,4,3,2,1,2,4,5),nrow=4)
# w.prefs=matrix(data=c(2,3,1,4,5,3,1,2,4,5,5,4,1,2,3,1,4,5,2,3),nrow=5)
@floswald
floswald / poly-approx.r
Created September 10, 2011 19:26
R code for polynomial approximation example
# test polynomial interpolation code by interpolating points on a semi-circle
# using a different number of points each time.
# contents:
# 1) make.circle(degree) is a function that generates
# n=degree+1 data points (x,y) on a semicircle. this is the "data" we
# want to interpolate.
# 2) pinterp() makes polynomial interpolation on "data" of degree "degree"
# using degree+1 parameters
# 3) run() is a wrapper that runs the interpolation
@floswald
floswald / hits.R
Created September 2, 2011 11:08
hits on website
# load data
hdata <- read.csv("helpdesk log.csv",header=TRUE,sep=",")
hdata$date <- as.Date(hdata$Timestamp,format="%m/%d/%Y") # Timestamp is in mm/dd/YYYY format
daycount <- table(hdata$date) # count how many hits per day
# daycount is what I call the "short" vector. It misses some days.
##################################
# daily response wrong graph