Skip to content

Instantly share code, notes, and snippets.

@dill
dill / README
Last active August 28, 2024 12:27
McDonnellbot
Thanks to wikipedia for the data :)
@dill
dill / all_the_single_palettes.txt
Last active November 11, 2015 16:21
👑🐝 All the single palettes 👑🐝 (one line per palette)
#273649 #647184 #B1B2C8 #A7755D #5D2E1C #38201C
#0F2B5F #5991C7 #8EC1E7 #B9DBF1 #D5A370 #7B4F37
#5A7362 #6B867C #A1A897 #9A8D6B #8E6341 #432B21
#1F150D #2B190C #513B2C #9B4D44 #893D37 #3E1B17
#9C8A45 #CABE85 #678B88 #9CADAF #CCCCCC #EFEFEF
#1C3333 #226060 #639CA4 #D2AD7C #BE7245 #46211C
#0D1723 #112040 #204D88 #96ABC6 #D1DDE2 #EFEFEF
#000000 #350E16 #5E1521 #A72C29 #C44221 #EC702E
#A56B47 #C79982 #0D8EDA #23ADED #6BC6F5 #EFEFEF
#2A2432 #4F3855 #846D86 #EFEFCF #D5B77D #A89E5E
@dill
dill / exif_plot.R
Created November 8, 2015 04:35
Goofy plotting of EXIF data
# get EXIF and make a map
library(leaflet)
library(lubridate)
library(plyr)
# all my photos are in a directory pre with subdirectories
pre <- "~/Dropbox/Photos/"
paths_to_photos <- c("some_sub_directory"
)
@dill
dill / extra_plot.R
Last active October 29, 2015 13:29
Make GAM term plots that extend outside the range of the data to show how bad extrapolation is for Laura M
load("best_model.Rdata")
library(dsm)
library(raster)
# lazily get the plot data for the rug plot
plotdat <- plot(M)
# load the raster and mudge it into the format I want
dists <- stack("NA_Shore_Dist_10km_mean_10km.img")
dists <- as.data.frame(dists)
### analysis of ribbon seal data using a frequentist
### approach to a GAM
### David L Miller [email protected]
### License: GNU GPL v3
# load data from
# https://github.com/pconn/SpatPred/blob/master/SpatPred/data/Ribbon_data.rda
load("Ribbon_data.rda")
@dill
dill / base_graphics.R
Last active October 14, 2015 19:41
Comparison of plotting covariates against distance, base graphics vs. ggplot2
# plot of size versus distance and sea state versus distance
# w. linear model and LOESS smoother overlay
# base graphics
par(mfrow=c(1,2))
plot(distdata[c("size","distance")], xlab="Group size", ylab="Distance (m)",pch=19,col=rgb(0,0,0,0.4), cex=0.6)
# increase span from default 0.75 for slightly smoother curve
lo <- loess(distance ~ size, distdata, span=0.8)
lmm <- lm(distance ~ size, distdata)
preddat <- data.frame(size=seq(0,8,1))
@dill
dill / example.R
Last active August 27, 2016 17:00
Visualising concurvity between terms in a GAM
# example from ?mgcv::concurvity
library(mgcv)
## simulate data with concurvity...
set.seed(8);n<- 200
f2 <- function(x) 0.2 * x^11 * (10 * (1 - x))^6 + 10 *
(10 * x)^3 * (1 - x)^10
t <- sort(runif(n)) ## first covariate
## make covariate x a smooth function of t + noise...
x <- f2(t) + rnorm(n)*3
@dill
dill / wiggly.R
Last active October 9, 2015 14:43
Goofy animation of integrating 2nd derivatives for a GAM penalty
# David L Miller 2015, MIT license
library(numDeriv)
library(animation)
# function taken from the "Gu & Wahba 4 term additive example" from mgcv::gamSim
f2 <- function(x) 0.2*x^11*(10*(1-x))^6+10*(10*x)^3*(1-x)^10
xvals <- seq(0,1,len=100)
@dill
dill / mrf-time.R
Created September 4, 2015 18:50
Example of Markov Random Field with temporal interaction
# Markov Random Fields with temporal interactions
# David L Miller 2015
# 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)
data(columb) ## data frame
@dill
dill / verhoef.R
Created August 28, 2015 03:18
ver Hoef and Boveng (2007) plots
# makes plots (somewhat) like those in ver Hoef and Boveng (2007)
# Jay M. Ver Hoef and Peter L. Boveng 2007. QUASI-POISSON VS. NEGATIVE BINOMIAL REGRESSION: HOW SHOULD WE MODEL OVERDISPERSED COUNT DATA? Ecology 88:2766–2772. http://dx.doi.org/10.1890/07-0043.1
# http://www.utstat.utoronto.ca/reid/sta2201s/QUASI-POISSON.pdf
# calling with something like:
# par(mfrow=c(1,2))
# # define the breaks