Skip to content

Instantly share code, notes, and snippets.

Gavin Simpson gavinsimpson

Block or report user

Report or block gavinsimpson

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@gavinsimpson
gavinsimpson / maddy-peat.csv
Created Jun 16, 2018
peat age data from maddy and drew
View maddy-peat.csv
Sample upperDepth lowerDepth ageBP ageError calUpper calLower
SRR-4556 20 22 355 35 509 307
SRR-4557 26 28 465 35 542 480
SRR-4558 32 34 635 35 671 545
SRR-4559 38 40 740 35 732 666
SRR-4560 44 46 865 35 916 691
SRR-4561 50 52.5 870 35 918 692
SRR-4562 56 58 985 35 967 795
SRR-4563 100 108 1270 35 1284 1097
SRR-4564 200 207 2575 35 2761 2558
View darlingtonia.csv
We can make this file beautiful and searchable if this error is corrected: Illegal quoting in line 1.
## leafHeight is in cm.; visited, 1 == TRUE, 0 == FALSE"
"leafHeight","visited"
67,1
84,1
49,1
70,1
77,1
77,1
66,1
65,1
@gavinsimpson
gavinsimpson / geochimica-metals.csv
Created Oct 10, 2017
Subset of data used in Rose et al (2012) Geochimica et Cosmochimica Acta 82, 113–135 doi: http://doi.org/10.1016/j.gca.2010.12.026
View geochimica-metals.csv
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 2 columns, instead of 5. in line 1.
## Subset of data used in Rose et al (2012) Geochimica et Cosmochimica Acta 82, 113–135 doi: http://doi.org/10.1016/j.gca.2010.12.026
SiteCode,Date,SoilType,Region,Hg
CHNA,2000,thin,NW,3.84339855275794
CHNA,1990,thin,NW,5.42461797827638
CHNA,1980,thin,NW,8.81972984714937
CHNA,1970,thin,NW,11.4174572948292
CHNA,1960,thin,NW,16.513540420367
CHNA,1950,thin,NW,16.5120469510654
CHNA,1940,thin,NW,11.1888397621818
CHNA,1930,thin,NW,11.6222216338607
@gavinsimpson
gavinsimpson / compare-glmmTMB-with-mgcv.R
Last active Jul 21, 2017
A quick R script I knocked up to compare the glmmTMB and mgcv packages for fitting zero-inflated GLMMs to the Salamander and Owls data sets from Brooks et al (2017)
View compare-glmmTMB-with-mgcv.R
## Compare Brooks et al glmmTMB paper with mgcv
## Packages
library("glmmTMB")
library("mgcv")
library("ggplot2")
theme_set(theme_bw())
library("ggstance")
## Salamander
@gavinsimpson
gavinsimpson / modelled-nuuk-rainfall.png
Last active Mar 3, 2017
R code to download, extract, and fit a Tweedie GAM to monthly rainfall total time series from Nuuk, Greenland, using mgcv
@gavinsimpson
gavinsimpson / asciify.R
Last active Sep 7, 2016
Create a MySQL-like ASCII table of data
View asciify.R
asciify <- function(df, pad = 1, ...) {
## error checking
stopifnot(is.data.frame(df))
## internal functions
SepLine <- function(n, pad = 1) {
tmp <- lapply(n, function(x, pad) paste(rep("-", x + (2* pad)),
collapse = ""),
pad = pad)
paste0("+", paste(tmp, collapse = "+"), "+")
}
View onename
Verifying that +ucfagls is my blockchain ID. https://onename.com/ucfagls
@gavinsimpson
gavinsimpson / simulate.gamm.R
Last active Oct 26, 2018
S3 method for simulate() for "gamm" objects from package mgcv
View simulate.gamm.R
`simulate.gamm` <- function(object, nsim = 1, seed = NULL, newdata,
freq = FALSE, unconditional = FALSE, ...) {
if (!exists(".Random.seed", envir = .GlobalEnv, inherits = FALSE))
runif(1)
if (is.null(seed))
RNGstate <- get(".Random.seed", envir = .GlobalEnv)
else {
R.seed <- get(".Random.seed", envir = .GlobalEnv)
set.seed(seed)
RNGstate <- structure(seed, kind = as.list(RNGkind()))
@gavinsimpson
gavinsimpson / loadCET
Last active Nov 21, 2015
A simple function to load and process the CET data into a nice format for modelling
View loadCET
## read in the CET data
`loadCET` <- function() {
CET <- url("http://www.metoffice.gov.uk/hadobs/hadcet/cetml1659on.dat")
on.exit(close(CET))
cet <- read.table(CET, sep = "", skip = 6, header = TRUE,
fill = TRUE, na.string = c(-99.99, -99.9))
names(cet) <- c(month.abb, "Annual")
## remove last row of incomplete data
cet <- cet[-nrow(cet), ] # FIXME: this removes the last row regardless
## get rid of the annual too - store for plotting
You can’t perform that action at this time.