Skip to content

Instantly share code, notes, and snippets.

View floswald's full-sized avatar
👋

Florian Oswald floswald

👋
View GitHub Profile
@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
@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 / DAA.r
Created January 15, 2012 21:21
DAA code
# deferred acceptance algorithm after Gale and Shapley
# coded by florian oswald
# f.oswald@ucl.ac.uk
# 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 / 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 / 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 / googleVis_at_RSS_2012.Rmd
Created September 11, 2012 08:02 — forked from mages/googleVis_at_RSS_2012.Rmd
googleVis at RSS 2012
Creating interactive web graphs with R: Overview and googleVis tutorial
========================================
```{r results='asis', echo=FALSE, message=FALSE, tidy=FALSE}
library(googleVis)
df <- data.frame(Postcode=c("TF3 4JH", "EC1Y 8LX"),
Tip=c("Telford", "RSS"))
## Tree map
T <- gvisTreeMap(Regions, "Region", "Parent", "Val", "Fac",
options=list(width=250, height=150,
@floswald
floswald / rgl.r
Created October 3, 2012 11:38
demo for quasi-concave functions
# R script accompanying quasi-concave, concave etc note
if(!require(rgl)) install.packages('rgl')
require(rgl)
# setup data
nx <- 50 # points into x direction
ny <- 50 # points into y
@floswald
floswald / knitr.lyx
Created November 4, 2012 16:45
problem with lyx and knitr
#LyX 2.0 created this file. For more info see http://www.lyx.org/
\lyxformat 413
\begin_document
\begin_header
\textclass article
\use_default_options true
\begin_modules
knitr
\end_modules
\maintain_unincluded_children false
@floswald
floswald / country.r
Created January 29, 2013 14:20
country plot code
library(xlsx)
cdat <- read.xlsx(file="~/datasets/ReinhardRogoff/18_data.xls",sheetName="Aut.Ita.UK.US")
cdat <- cdat[,-c(5,6,7)]
library(reshape)
library(ggplot2)
m <- melt(cdat,c("Year","Country"))
p <- ggplot(m,aes(x=Year,y=value)) + geom_line(aes(color=variable),size=1) + facet_wrap(~Country,ncol=1) + scale_y_continuous(name="Public (Public and Private) debt to GDP (GNP) ratios") + theme(legend.position="top")
@floswald
floswald / benchmark.r
Created May 17, 2013 16:09
benchmarking armamax against apply and pmax
library(inline)
library(Rcpp)
cpp <- 'arma::mat A = Rcpp::as<arma::mat>(X_);
arma::vec y(A.n_rows);
arma::rowvec tmp(A.n_cols);
for (int i=0; i<A.n_rows; i++) {
tmp = A.row(i);
y(i) = tmp.max();
}