Skip to content

Instantly share code, notes, and snippets.

@dill
dill / uncertainty-anim.R
Last active February 23, 2017 16:55
Animations of uncertainty in density maps
# little animation to illustrate uncertainty in a density map
library(dsm)
library(mvtnorm)
library(ggplot2)
library(animation)
library(viridis)
# load the models and prediction data
# using data from the Duke spatial distance sampling course
@dill
dill / example.R
Created February 20, 2016 20:23
display R plots in iTerm2
library(ggplot2)
library(emoGG)
source("imgcat.R")
p <- ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) + geom_emoji(emoji="1f337")
imgcat(print(p))
@dill
dill / columb.R
Created August 5, 2016 03:33
Is Columus, OH the only place in the US where 1/2 the population is within 500 miles? Well, kinda
# is Columbus, OH really the only place in the US where you're within
# 500 miles of half of the US population?
# claim: https://448f59f74df57015bbb8-a9447b7dfa4ae38e337b359963d557c4.ssl.cf3.rackcdn.com/9987%20Brewdog%20EFP%20Prospectus%20USA%20A4%20v9.pdf
# "Columbus is within 500 miles of over half of the US population"
# get the US 2010 census data
# http://www2.census.gov/geo/docs/reference/cenpop2010/county/CenPop2010_Mean_CO.txt
cent <- read.csv("CenPop2010_Mean_CO.txt")
@dill
dill / the_empire_strikes_back.R
Last active August 26, 2016 03:42
End Imperialism! (in terms of units of length, at least) 📏 👍
# try to understand measurements from the past...
# possible input types:
# - 5
# - 5'
# - 5'5
# - 5'7 1/2
# - 5'7\"
# - 5'8.5
# - 5'61/2\"
@dill
dill / better_check.R
Last active September 14, 2021 17:09
Combined deviance and quantile residuals check plots for GAMs
library(gridBase)
library(grid)
library(mgcv)
library(statmod)
## nicer version of gam.check/rqgam.chack
# - deviance residuals for the Q-Q and histogram
# - RQR for resids vs linear pred
# - response vs fitted
# hist.p gives the quantiles of the residuals to show
better_check <- function(b, k.sample = 5000, k.rep = 200, rep = 0, level = 0.9,
@dill
dill / gridstuff.R
Last active April 7, 2017 00:59
grids in the right place
# make a boundary
library(mapdata)
library(maptools)
library(rgeos)
library(ggplot2)
library(sp)
# build the coastline
coastline <- map("world", c("USA", "Canada"), plot=FALSE)
@dill
dill / hi_len.R
Created May 22, 2017 19:02
Uncertainty estimation and plotting in dsm
# for LJT
# this wasn't as simple as I thought, it was the summary() method that does the smart thing
# so there is a bit of split() nonsense to deal with...
library(Distance)
library(dsm)
library(ggplot2)
@dill
dill / health.R
Created January 5, 2018 12:53
Do a quick analysis of the Health data collected by iPhones
library(XML)
# pull in the xml file
# can export this from the iPhone and e-mail it to youself
xx <- xmlParse("export.xml")
xx <- xmlToList(xx)
# now do some data mudging
library(plyr)
@dill
dill / howfar2017.R
Last active January 5, 2018 13:18
How far did I travel in 2017?
# how far did I go in 2017?
# read in the list of places I went to
txt <- readLines("howfar2017.txt")
# decode the place names to lat/long
library(ggmap)
gg <- geocode(txt, source="dsk")
@dill
dill / ebird_sp_disc.R
Created January 9, 2018 09:37
make an eBird species discovery curve
### species discovery curve from eBird
library(lubridate)
# life list
life <- read.csv("ebird_world_life_list.csv")
life$date <- lubridate::dmy(as.character(life$Date))
#sort
life <- life[order(life$date),]