This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# _____________ ____________ ____________ ___________________ | |
# \ ______ \__ _\ ______ \ _\ ______ \ _\ ___ \______ | |
# \ / \ \ \ \ \ \__ _\ \ \ \ \ _\ \ \/ \ \_____ | |
# \ / \ \ \ \ \ \ \ \ \ \ \ \__ _\ \ \ \ \ \____ | |
# \ /______ \ \ \ \_____\ \ \ \ \ \_____\ \ \ \ \ \ \ \ \___ | |
# \___________\__\_\___________\__\_\_\___________\__\_\_\_\___________\__ | |
# \____________\___\_\____________\___\_\_\____________\__ | |
# \____________\_____\_\____________\___ | |
# SPECIES DISTRIBUTION MODELLING \____________\____ | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
OlderNewer