Skip to content

Instantly share code, notes, and snippets.

View pboesu's full-sized avatar

Philipp Boersch-Supan pboesu

View GitHub Profile
@pboesu
pboesu / model.stan
Created January 11, 2021 22:10 — forked from MatsuuraKentaro/model.stan
Tweedie distribution in Stan
data {
int N;
int M;
real<lower=0> Y[N];
}
parameters {
real<lower=0> mu;
real<lower=0> phi;
real<lower=1, upper=2> theta;
@pboesu
pboesu / dist.R
Created June 24, 2020 07:03 — forked from mbjoseph/dist.R
Distance sampling in Stan
# Distance sampling model with data augmentation.
# Based on section 8.3.1 of the Applied Hierarchical Modeling book by Royle and Kery
library(rstan)
B <- 50
# note that I'm dividing by 10 and adding 1e-6 to put this on a manageable
# scale and prevent values == 0
d_obs <- c(71.93, 26.05, 58.47, 92.35, 163.83, 84.52, 163.83, 157.33,
@pboesu
pboesu / mgcv-posterior-animate.R
Created February 6, 2019 12:20 — forked from noamross/mgcv-posterior-animate.R
Animating smoothing uncertainty in a GAM
library(tidyverse)
library(gganimate)
library(mgcv)
library(mvtnorm)
# Fit a GAM to the data
mod <- gam(hp ~ s(mpg), data=mtcars, method="REML")
# Get the linear prediction matrix
newdat = data.frame(
@pboesu
pboesu / mtcars-cat.R
Last active November 18, 2016 10:47 — forked from dill/mtcars-cat.R
categorical emojis -- like this Mark?
library(emoGG)
library(ggplot2)
#use subsetting to display different emojis for different factor levels
ggplot(mtcars, aes(wt, mpg))+
geom_emoji(data = mtcars[mtcars$am==1, ], emoji = "1f697") +
geom_emoji(data = mtcars[mtcars$am==0, ], emoji = "1f68c")
### Title: Back to basics: High quality plots using base R graphics
### An interactive tutorial for the Davis R Users Group meeting on April 24, 2015
###
### Date created: 20150418
### Last updated: 20150423
###
### Author: Michael Koontz
### Email: mikoontz@gmail.com
### Twitter: @michaeljkoontz
###
require(quantmod)
require(fAssets)
#get asian currency data from the FED FRED data series
getSymbols("DEXKOUS",src="FRED") #load Korea
getSymbols("DEXMAUS",src="FRED") #load Malaysia
getSymbols("DEXSIUS",src="FRED") #load Singapore
getSymbols("DEXTAUS",src="FRED") #load Taiwan
getSymbols("DEXCHUS",src="FRED") #load China
getSymbols("DEXJPUS",src="FRED") #load Japan