Skip to content

Instantly share code, notes, and snippets.

@dill
dill / failwhale
Created June 12, 2015 22:16
a red failwhale for @awegalloway
library(rphylopic)
# get a (sperm) whale! (this is "Physeter catodon" by Noah Schlottman)
# http://phylopic.org/image/dc76cbdb-dba5-4d8f-8cf3-809515c30dbd/
whale <- image_data("dc76cbdb-dba5-4d8f-8cf3-809515c30dbd", size=512)
# failwhale
image(whale[[1]][,,4])
@dill
dill / rverbr.R
Last active April 15, 2020 22:03
Make JSON for @RverbR
## This is a very silly script to get JSON data for an R twitter bot that produces
## tweets of the form "verb that noun" using verbs from package:base and nouns from
## built in R data.
##
## It uses @v21's http://cheapbotsdonequick.com/
##
## David L. Miller 2015 MIT license
## update from Nick Golding 2018
cat("{\n")
@dill
dill / get_res.R
Created May 31, 2015 00:05
UN Resolutions downloader
# get UN resolutions
# Annoyingly the UN website is not very crawl-able.
# Using RSelenium you can download Resolution data
library(RSelenium)
library(stringr)
# download directory
dl_dir <- path.expand("~/Downloads/UN69/")
@dill
dill / gist:2d1baac441db6fd60764
Last active August 29, 2015 14:18
useR! 2015 abstract

Building ecological models bit-by-bit

Many models that we build rely on combining several components, often representing different processes at work in the system. For example in ecology we may have a component for detectability of the species by observers, one for whether the animals are available, one describing their spatial distribution.

Defining such a complex model in R can result in writing a very long call to a particular function, which may or may not work at any point. Since these processes are often (conditionally) independent, we can separate these components in the likelihood and code. Using the + operator we can then combine them in a simple way that's easy for those doing the modelling to understand. Since each step produces an object, we can perform model validation, diagnostics and checking during construction.

Through an example applied to distance sampling, I'll show an example of this kind of approach to model building and propose some other situations where this kind of strategy may

@dill
dill / abstract.md
Last active August 29, 2015 14:16
ESA 2015 abstract

Background/Question/Methods

Our understanding of a biological population can be greatly enhanced by modelling their distribution in space and as a function of environmental covariates. Such models can be used to investigate the relationships between distribution and environmental covariates as well as reliably estimate abundances and create maps of animal and plant distributions.

Here I'll give an overview of "density surface models", which consist of a spatial model of the abundance which has been corrected for uncertain detection via distance sampling methods. The spatial model consists of a generalised additive (mixed) model, which can include various components, such as smooth terms and random effects.

Results/Conclusions

In particular, I'll highlight modelling techniques that may be advantageous to applied ecologists: quantification of uncertainty in a two-stage model, correction for availability bias, alternative response distributions, autocorrelation and smoothing in areas with complex bound

@dill
dill / yosemiteR.md
Last active October 25, 2015 19:09
Getting Yosemite and R to play nice...

Getting Yosemite and R to play nice

Here are some tips on getting R development working with Yosemite. Contribute what you know below and I'll add it in.

homebrew

I went ahead and re-installed all of my homebrew. You can find out what you have installed with

@dill
dill / plots.R
Created September 21, 2014 20:39
Transformation of variables in a GAM
# R plotting routines for the package mgcv (c) Simon Wood 2000-2010
## With contributions from Henric Nilsson
plot.mgcv.smooth <- function(x,P=NULL,data=NULL,label="",se1.mult=1,se2.mult=2,
partial.resids=FALSE,rug=TRUE,se=TRUE,scale=-1,n=100,n2=40,
pers=FALSE,theta=30,phi=30,jit=FALSE,xlab=NULL,ylab=NULL,main=NULL,
ylim=NULL,xlim=NULL,too.far=0.1,shade=FALSE,shade.col="gray80",
shift=0,trans=I,by.resids=FALSE,scheme=0,...) {
## default plot method for smooth objects `x' inheriting from "mgcv.smooth"
@dill
dill / distanim.R
Last active November 25, 2023 06:20
Animation of a simple distance sampling survey.
# animate a (very boring) distance sampling survey
# watch a gif at: http://converged.yt/distance-animation.gif
# written by David Lawrence Miller, with tweaks from Eric Rexstad
# released under the MIT license
library(animation)
# make sure that we get the same result every time...
set.seed(1234)
@dill
dill / fw2dot.R
Created January 27, 2014 20:48
Build a GraphViz compatible file showing which functions call each other in an R package.
# use MVB's foodweb to build a graphviz-compatible "dot" file
# this can then be used to generate a svg of the graph using:
# $ dot -Tsvg file.dot -o file.svg
# example usage:
# fw2dot("mrds","mrds.dot")
library(mvbutils)
fw2dot <- function(package.name,filename){
@dill
dill / alarm.sh
Last active December 24, 2015 20:59
alarm clock
#!/bin/bash
# alarm clock script
#
# requires: get-iplayer
# git clone [email protected]:dinkypumpkin/get_iplayer.git
# get_iplayer --prefs-add --rtmp-tv-opts="--swfVfy=http://www.bbc.co.uk/emp/releases/iplayer/revisions/617463_618125_4/617463_618125_4_emp.swf"
# need to install rtmpdump