This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Markov Random Fields with temporal interactions | |
# based on https://gist.github.com/dill/ecfe7d2f0e542bb274ff | |
# David L Miller 2020 | |
# Released under MIT license, YMMV | |
# example from ?mgcv::smooth.construct.mrf.smooth.spec | |
library(mgcv) | |
## Load Columbus Ohio crime data (see ?columbus for details and credits) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# extrapolating into the future with B-splines | |
# based on code in ?smooth.construct.bs.smooth.spec | |
library(mgcv) | |
# annual diameter of women’s skirts at the hem 1866 to 1911 | |
# Hipel and McLeod, 1994 | |
skirts <- scan("http://robjhyndman.com/tsdldata/roberts/skirts.dat",skip=5) | |
skirtseries <- data.frame(year=1866:1911, diam=skirts) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(mgcv) | |
set.seed(2) ## simulate some data... | |
dat <- gamSim(1,n=400,dist="normal",scale=2) | |
b <- gam(y~s(x1), data=dat, fit=FALSE) | |
newpred <- data.frame(x1=seq(0, 10, length.out=100)) | |
# Lp for the data | |
lp_data <- PredictMat(b$smooth[[1]], dat) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Tax data from NYT article | |
# data scraped from https://www.nytimes.com/interactive/2019/10/06/opinion/income-tax-rate-wealthy.html | |
# load data scraped from SVG | |
tax <- readLines("taxdat.dat") | |
taxy <- c() | |
for(i in 1:length(tax)){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# generate some relaxing cloudy sky squares | |
# | |
# David Lawrence Miller (2019) | |
library(INLA) | |
library(ggplot2) | |
## function to simulate spatial fields | |
simdat <- function(n, seed, prior.range = c(5, .05), | |
prior.sigma = c(.05, .05)){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# data digitized from https://twitter.com/nberpubs/status/1062080096549261312 | |
# thanks @tpoi and co! https://cran.r-project.org/web/packages/digitize/index.html | |
# load the above data | |
dat <- read.csv("nber.csv") | |
# it's ya boi, mgcv | |
library(mgcv) | |
# fit the next stupidest model |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tax_rate | tax_rev | |
---|---|---|
0.07357329 | -0.0567062 | |
8.81285407 | 2.4505785 | |
12.84385295 | 3.5807126 | |
16.23680790 | 2.1860302 | |
19.18260073 | 2.4643621 | |
19.29050823 | 1.9514672 | |
18.45218145 | 1.2480201 | |
26.73285538 | 1.5886201 | |
22.37159417 | 3.3657369 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hat | Season | Episode | |
---|---|---|---|
Thick | 6 | 9 | |
Wet To Activate | 4 | 3 | |
Ho Ho Horny | 2 | 9 | |
Horny | 3 | 1 | |
Horny | 3 | 1 | |
Rods | 1 | 9 | |
Feet | 6 | 6 | |
Feet | 6 | 7 | |
Squeeze It | 1 | 15 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# average predictions | |
library(Distance) | |
library(dsm) | |
# download data from http://workshops.distancesampling.org/stand-intermed-2018/practicals/spermwhale.RData | |
load("spermwhale.RData") | |
# make sure we get the same results every time | |
set.seed(123) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# little animation to illustrate uncertainty in a density map | |
library(dsm) | |
library(mvtnorm) | |
library(ggplot2) | |
library(animation) | |
library(viridis) | |
library(cowplot) | |
set.seed(1997) |