Skip to content

Instantly share code, notes, and snippets.

@goldingn
goldingn / CUR4FIC
Last active January 3, 2016 05:49
Playing with CUR decomposition (versus k-means) as a method for picking inducing points in sparse Gaussian processes
# clear the workspace
rm(list = ls())
# load the relevant libraries
# install.packages(rCUR)
library(rCUR) # for CUR decomposition
# install.packages(irlba)
library(irlba) # for fast svd
@goldingn
goldingn / pop_maxent.R
Created May 12, 2014 10:44
Playing with probability-of-presence from Maxent-type models
# converting maxent/Poisson model output to true probability of presence
# clear workspace
rm(list = ls())
# set rng seed
set.seed(1)
# number of datapoints
n <- 100000
@goldingn
goldingn / zoon_sketch.R
Created June 17, 2014 17:12
Rough sketch of ZOON modular structure
# _____________ ____________ ____________ ___________________
# \ ______ \__ _\ ______ \ _\ ______ \ _\ ___ \______
# \ / \ \ \ \ \ \__ _\ \ \ \ \ _\ \ \/ \ \_____
# \ / \ \ \ \ \ \ \ \ \ \ \ \__ _\ \ \ \ \ \____
# \ /______ \ \ \ \_____\ \ \ \ \ \_____\ \ \ \ \ \ \ \ \___
# \___________\__\_\___________\__\_\_\___________\__\_\_\_\___________\__
# \____________\___\_\____________\___\_\_\____________\__
# \____________\_____\_\____________\___
# SPECIES DISTRIBUTION MODELLING \____________\____
#
@goldingn
goldingn / geti
Created October 8, 2014 10:28
return the elements of an array of unknown dimension at the ith index on the first dimension
geti <- function (x, i) {
# return the elements of an array `x` of unknown dimension
# at the ith index of its first dimension
# throw an error if x isn't an array
stopifnot(is.array(x))
# get the dimension of x
k <- length(dim(x))
@goldingn
goldingn / fuzzyMatch.R
Created October 29, 2014 17:47
no frills fuzzy matching for character vectors in R
fuzzyMatch <- function (a, b) {
# no-frills fuzzy matching of strings between character vectors
# `a` and `b` (essentially a wrapper around a stringdist function)
# The function returns a two column matrix giving the matching index
# (as `match` would return) and a matrix giving the distances, so you
# can check how well it did on the hardest words.
# Warning - this uses all of your cores.
# load the stringdist package
@goldingn
goldingn / circleplot_mre.R
Created November 21, 2014 13:29
minimal reproducible example of the bug in circleplot
# load devtools and install the preferred version of circleplot
library(devtools)
install_github('mjwestgate/circleplot')
#install_github('goldingn/circleplot')
library(circleplot)
# set RNG seed
set.seed(1)
# create a fake symmetric matrix
@goldingn
goldingn / sophie_davison_barplot.R
Created July 21, 2015 14:49
barplot on binomial GLM results as an option for this series of tweets: https://twitter.com/SophDavison1/status/623491784530915328
# set RNG seed
set.seed(1)
# make some fake data
n <- 100
m <- 5
y <- rbinom(n, 1, 0.85)
x <- sample(letters[1:m], n, replace = TRUE)
# fit a logistic regression model
@goldingn
goldingn / rstudio_external.sh
Last active August 29, 2015 14:25
Tweak RStudio desktop on OSX to put plots and docs in external windows
#!/bin/bash
# modify RStudio's options to send plots to quartz by default,
# and open help and local html in the default browser
echo "
# ~~~~~~~~~~~
# Tweaks to view help and html in the browser, and plots in quartz, not the RStudio viewer pane
browser <- '/usr/bin/open'
device <- 'quartz'
@goldingn
goldingn / docker_rstudio.sh
Last active September 13, 2015 15:46
short bash script to start a docker rstudio-server instance on OSX
#!/bin/bash
# Trigger an Rstudio-server instance in docker, linked to the current filesystem
# and open in a browser.
# **WARNING** this will create a .gitconfig file in the working directory, potentially overwriting one that's already there!
# it will also create a .rstudio folder, and possibly other things
# This script should be run from the Docker Quickstart Terminal on OSX.
# I.e. it uses the an up-to-date docker installation which handles the VM side of things, *not boot2docker*
# make a nice viridis GMRF tesselation for Richard
rm(list = ls())
set.seed(1)
library(INLA)
library(raster)
library(viridis)
library(fields)
# grid sizes for sampling the GRF and for the final image