Skip to content

Instantly share code, notes, and snippets.

Jarrett Byrnes jebyrnes

Block or report user

Report or block jebyrnes

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jebyrnes
jebyrnes / addZeroes.R
Last active Aug 29, 2015
A demonstration of how to add rows with zeroes using melt and dcast. There are other ways, but this is pretty simple.
View addZeroes.R
################################
# 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 Mar 31, 2014
A multifunctionality analysis using the threshold effect for Biodepth in Germany using the Zissou color scheme from Karthik's wesanderson package for color palates.
View germany_biodepth_zissou.R
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)
View new_multifunc.R
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 Oct 23, 2014
misbehaving_dcov.Rnw
View dcov.test
\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 Aug 29, 2015
Plotting in 3D in R
View scatterPlot3d.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 / leafletMapWithLegend.R
Last active Aug 29, 2015
A demo of leaflet using a color legend
View leafletMapWithLegend.R
#devtools::install_github("rstudio/leaflet", ref="feature/color-legend")
library(leaflet)
library(RColorBrewer)
set.seed(100)
pdf <- data.frame(Latitude = runif(100, -90,90), Longitude = runif(100, -180,180))
#make a property with colors
pdf$Study <- rep(1:10,10)
#need to create a pal using colorbin
@jebyrnes
jebyrnes / sims3.r
Created May 19, 2011
Simulations of beta regression as compared to other techniques designed for working on response variables on a unit (0,1) scale.
View sims3.r
######
#script to generate simulations comparing the power and type I error rate
#of a variety of different methods of analyzing response variables on a unit (0-1) scale
#
# Inspired by "The Arcsine is Asinine" in a 2011 issue of Ecology
#
# byrnes@nceas.ucsb.edu
# last updated 5/19/11
#
# Changelog: Added visualization code
@jebyrnes
jebyrnes / projects.csv
Created Nov 13, 2011
Code to scrape RocketHub's xml feeds for the #SciFund projects, add it to a log file, then plot it. Run the data scrape without appending the first time to generate a log file.
View projects.csv
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 9.
"ID","Title","Name","Project.Link","Goal"
1,"Why is this Dolphin's Fin on Backwards!?","Matthew S. Leslie","http://www.rockethub.com/projects/3754-why-is-this-dolphin-s-fin-on-backwards","5000"
2,"Tracking the migration of the Atlantic Puffin","Robin Freeman","http://www.rockethub.com/projects/3818-tracking-the-migration-of-the-atlantic-puffin","5000"
3,"Cancer? Yeast has the answers","Marisa Alonso-N??ez","http://www.rockethub.com/projects/3753-cancer-yeast-has-the-answers","2500"
4,"Athlete's Foot in Worms?","Rebecca Rashid Achterman","http://www.rockethub.com/projects/3703-athlete-s-foot-in-worms","1000"
5,"Support Zombie Research!","Kelly Weinersmith","http://www.rockethub.com/projects/3737-support-zombie-research","3500"
6,"Doctor Zen and the Amazon Crayfish","Zen Faulkes","http://www.rockethub.com/projects/3695-doctor-zen-and-the-amazon-crayfish","1000"
7,"C-Cilia in Motion!!","Aditya Rao","http://www.rockethub.com/projects/3792-c-cilia-in-motion","5000"
8,"Force of Duck: Measuring explosive erection","
@jebyrnes
jebyrnes / allPredPrey.r
Created Dec 7, 2011
Simulations of all predators and prey applying the p(eaten) formula for a probabilistic approach to food webs
View allPredPrey.r
###############FUNCTIONS
#If you find the 0 predators remaining formulation more intuitive
pEaten2<-function(Sp.max, E, prey.vec) {
1-mean(dhyper(0,prey.vec, Sp.max-prey.vec, Sp.max-E))
}
#vectorize it
pEaten2<-Vectorize(pEaten2, vectorize.args="E")
#generate all permutations of prey being eaten
@jebyrnes
jebyrnes / iworkfortheinternet.R
Created Dec 14, 2011 — forked from sckott/iworkfortheinternet.R
Code for searching Twitter using the twitteR #rstats package.
View iworkfortheinternet.R
require(plyr); require(stringr); require(ggplot2); require(lubridate); require(twitteR)
##need to figure out why there are two datout objects and not just 1...
twitterPlot<-function(myString, n=1500, since=NULL, until=NULL){
since2<-as.character(strptime(since, '%Y-%m-%d')+2*24*60*60)
until2<-as.character(strptime(until, '%Y-%m-%d')+2*24*60*60)
datout_1 <- searchTwitter(myString, n = n, since=since, until=until)
datout_2 <- searchTwitter(myString, n = n, since=since2, until=until2)
You can’t perform that action at this time.