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 / albatross_eggs_header.Rmd
Created May 21, 2020 13:45
albatross_eggs_header.Rmd
---
title: "Surface temperatures of albatross eggs and nests"
author: Philipp H. Boersch-Supan^A,B,C^, Leah R. Johnson^D^, Richard A. Phillips^E^,
Sadie J. Ryan^A,B^
date: ''
output:
word_document:
keep_md: yes
reference_docx: marine_ornithology_style_ref.docx
pdf_document:
@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(
library(dplyr)
system.time(df3 <- left_join(select(df1, lat, lon, id, time_hour),
select(df2, lat, lon, var1, var2, time_words),
by = c('lat', 'lon', 'time_hour' = 'time_words')
)
)
#21.37 seconds
@pboesu
pboesu / 20180807jennis_challenge.R
Last active August 7, 2018 11:28
Jenni's coding challenge
require(dplyr)
nuts1 <- readr::read_csv('NUTS1_kmsq.csv')
nuts1 %>% group_by(ONEKMREF) %>% summarise(biggest_area = max(kmsq_Area), biggest_area_index = which.max(kmsq_Area), biggest_area_name = Region_name[biggest_area_index] ) -> solution_df
#check for areas with multiple regions
nuts1 %>% group_by(ONEKMREF) %>% summarise(n_rows = n()) %>% arrange(desc(n_rows)) %>% head()
@pboesu
pboesu / academic_moves.Rmd
Created February 17, 2018 16:00
Academic moves
---
title: "Academic moves"
author: "Philipp Boersch-Supan"
date: "2018-02-17"
output:
html_document:
keep_md: yes
---
gc()
#devtools::install_github("pboesu/rucrdtw", ref = "expose_distance_calculations")
library(rucrdtw)
set.seed(12444)
x = rnorm(10^4)
y = rnorm(10^4)
gctorture(on = TRUE)
for (i in 1:(2*10^3)) {
@pboesu
pboesu / Hytool_example
Created July 12, 2017 20:17
"Getting started" example run on MATLAB R2014b
Warning: Function cummax has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.
>> edit ths_ds1.dat
>> [t,s]=ldf('ths_ds1.dat');
clf
plot(t,s,'o')
xlabel('Time in seconds')
ylabel('Drawdown in meters')
title('The Fetter data set')
>> diagnostic(t,s)
Attempted to access Dk(:,2); index out of bounds because
@pboesu
pboesu / antipodes.sh
Last active December 8, 2016 20:26
GMT scripts for Enderby Trip visualisation
#!/bin/bash
# This map is a quick and dirty adaptation of GMT EXAMPLE 25
# (using GMT 5.4.0_r17345)
# Purpose: Display distribution of antipode types around NZ
# GMT modules: gmtset, grdlandmask, grdmath, grd2xyz, gmtmath, grdimage, pscoast, pslegend
# Unix progs: cat
#
# Create D minutes global grid with -1 over oceans and +1 over land
D=10
gmt grdlandmask -Rg -I${D}m -Dc -A500 -N-1/1/1/1/1 -r -Gwetdry.nc