Skip to content

Instantly share code, notes, and snippets.

@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 / 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*
@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
# devtools::install_github("briatte/ggnet")
library(network)
library(sna)
library(ggplot2)
library(viridis)
library(ggnet)
# random graph
set.seed(1)
n <- 500
@goldingn
goldingn / zoon_module_lookup.R
Last active May 27, 2016 08:16
functions to create a version/sha lookup table for modules
# functions to compile a package/version-sha lookup table
library(git2r)
ModuleVersion <- function (modulePath, version_string = '^Version: ') {
# given a path to a module, return the module version, or NA if it doesn't
# have one
# copy the roxygen header to a temporary file, in case the R code is unparseable
file.create(f <- tempfile())
lines <- readLines(modulePath, warn = FALSE)