Skip to content

Instantly share code, notes, and snippets.

View jebyrnes's full-sized avatar

Jarrett Byrnes jebyrnes

View GitHub Profile
@jebyrnes
jebyrnes / dunnet.R
Last active December 31, 2015 02:09
Dunnett's test using means, standard deviations, and sample sizes
###########
# Calculate a Dunnett's test
# using information from a meta-analysis
# using definitions at http://davidmlane.com/hyperstat/B112114.html
#
# Jarrett Byrnes
# 12/8/2013
###########
#helper functions
@jebyrnes
jebyrnes / snowfun.r
Last active December 31, 2015 07:09
How much snow we might get, and where is the fun zone.
#the range of possible snow
minsnow <- 0
maxsnow <- 12 #1 foot - WOOOO!!!
#a range of snow values
snowdist <- seq(minsnow, maxsnow, 0.01)
len <- length(snowdist)
#let's assume a log normal distribution of the snow
#we might get, with a conservative mean of ~1
@jebyrnes
jebyrnes / getOrderEOL.R
Created January 28, 2014 19:46
A quick script to get the order of a species if you know it's latin binomial name using the Reol library http://cran.r-project.org/web/packages/Reol/index.html
library(Reol)
getOrder <- function(binom_taxa, db = "NCBI Taxonomy"){
MyEOLs <- DownloadSearchedTaxa(binom_taxa, to.file=FALSE)
hier <- DownloadHierarchy(MyEOLs, FALSE, database=db)
taxonomic_info <- CombineHierarchyInfo(hier)
ord <- which(taxonomic_info[[2]]=="Order")
return(taxonomic_info[[1]][ord,1])
}
@jebyrnes
jebyrnes / addZeroes.R
Last active August 29, 2015 13:56
A demonstration of how to add rows with zeroes using melt and dcast. There are other ways, but this is pretty simple.
################################
# Problem: You have a ragged
# data frame where species that have not
# been seen as a site simply don't have a
# line in your data frame. You have a long
# data frame, but you want a long data frame
# where missing species have proper zeroes
#
# Solution: a combination of dcast and melt
# from the reshape2 package
@jebyrnes
jebyrnes / germany_biodepth_zissou.R
Created March 31, 2014 21:25
A multifunctionality analysis using the threshold effect for Biodepth in Germany using the Zissou color scheme from Karthik's wesanderson package for color palates.
library(multifunc)
library(wesanderson)
data(all_biodepth)
allVars<-qw(biomassY3, root3, N.g.m2, light3, N.Soil, wood3, cotton3)
germany<-subset(all_biodepth, all_biodepth$location=="Germany")
vars<-whichVars(germany, allVars)
#re-normalize N.Soil so that everything is on the same sign-scale (e.g. the maximum level of a function is the "best" function)
@jebyrnes
jebyrnes / getSpaldingRegions.R
Created June 10, 2014 17:50
Script to get Spalding's Marine Ecoregions of the World in R from lat/long data and a GIS file.
############################################################################################
#
# Script to turn lat/long data into
# marine ecoregions using Spalding's Marine Ecoregions
# of the World (MEOW).
#
# To run, first acquire the appropriate GIS files from
# http://maps.tnc.org/gis_data.html and unzip them into
# a directory (MEOW-TNC) - then go from there.
#
library(multifunc)
data(all_biodepth)
allVars<-qw(biomassY3, root3, N.g.m2, light3, N.Soil, wood3, cotton3)
germany<-subset(all_biodepth, all_biodepth$location=="Germany")
vars<-whichVars(germany, allVars)
#re-normalize N.Soil so that everything is on the same sign-scale (e.g. the maximum level of a function is the "best" function)
germany$N.Soil<- -1*germany$N.Soil +max(germany$N.Soil, na.rm=TRUE)
@jebyrnes
jebyrnes / dcov.test
Created October 23, 2014 19:09
misbehaving_dcov.Rnw
\documentclass{article}
\begin{document}
<<echo=FALSE>>=
activityDF <- structure(list(julian_day = 1:365, food = c(92.6182247978374,
199.361820535986, 128.619308542186, 131.048504694701, 44.6344539529983,
139.02542881751, 118.815437972886, 85.5963235153311, 73.9459098960665,
85.6671795660157, 195.954639346317, 192.942941724749, 193.341526021202,
142.419581610027, 130.23002915561, 232.843857188757, 105.14817987285,
131.58751463704, 123.30056211349, 150.447279408636, 138.40775613945,
@jebyrnes
jebyrnes / scatterPlot3d.R
Last active August 29, 2015 14:10
Plotting in 3D in R
#just create a range of values
grdVals <- function(x, bound=0.01) seq(range(x)[1]-bound, range(x)[2]+bound, length.out=50)
#instantiate a new persp object for a scatterplot
makeScatterBox <- function(x,y,z, bound=0, ...){
x <- grdVals(x, bound=bound)
y <- grdVals(y, bound=bound)
z <- grdVals(z, bound=bound)
z <- matrix(rep(z, 50), nrow=50)
@jebyrnes
jebyrnes / meow_plot_base.R
Last active November 25, 2020 04:10
Basic methods for dealing with shapefiles for marine ecoregions of the world.
#########################################################################
# Code to import and make useful
# Spalding et al. 2007's Marine Ecoregions of the World
# Data provided by http://www.marineregions.org/downloads.php
# by Jarrett Byrnes
# last updated 3/26/2015
#########################################################################
######################
##### Load Libraries