Skip to content

Instantly share code, notes, and snippets.

View jebyrnes's full-sized avatar

Jarrett Byrnes jebyrnes

View GitHub Profile
@jebyrnes
jebyrnes / sims3.r
Created May 19, 2011 17:35
Simulations of beta regression as compared to other techniques designed for working on response variables on a unit (0,1) scale.
######
#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 November 13, 2011 00:23
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.
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 December 7, 2011 23:06
Simulations of all predators and prey applying the p(eaten) formula for a probabilistic approach to food webs
###############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 December 14, 2011 01:26 — forked from sckott/iworkfortheinternet.R
Code for searching Twitter using the twitteR #rstats package.
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)
@jebyrnes
jebyrnes / goal_success_scifund.R
Created February 28, 2012 23:16
Analysis code for looking at the relationship between project goal and % success from #SciFund. Note, I did it with my own private data set that has a lot of merged fields in it, but you can run this analysis or something like it with Zen's data at http:
source("./sciFundFunctions.r")
library(gridExtra)
#################################################
#######HISTOGRAMS
#################################################
#total raised histogram distribution
raised<-qplot(total, data=projects) +
theme_bw(base_size=16) +
xlab("\nTotal Raised") +
@jebyrnes
jebyrnes / pageviews.R
Created March 6, 2012 19:00
Analysis code for looking at the relationship between page views and dollars raised for #SciFund
source("./sciFundFunctions.r")
library(gridExtra)
############
#Begin with a plot of both with and without the outlier
############
viewsAll<-qplot(Pageviews, total, data=projects)+theme_bw(base_size=24) + ylab("Total Dollars Raised\n") +
xlab("\nPage Views") +
@jebyrnes
jebyrnes / Maestre_reanalysis.R
Created April 23, 2012 23:05
Code to Re-Analyze the results of Maestre et al 2012 Spurred on by Bob O'Hara, Jeremy Fox, and Ted Hart's ongoing discussions
########################################################################################################
# Re-Analysis of Maestre et al 2012
# examining relationship between biodiversity and ecosystem multifunctionality
# Paper and data included as a supplement can be found at http://dx.doi.org/10.1126/science.1215442
########################################################################################################
######################
####### First, let's look at standardized regression coefficients
####### Both for the best fit model, but also for the model averaged coefficients
######################
@jebyrnes
jebyrnes / martine.R
Created September 27, 2012 19:56
Martine's Code
enthus <- read.csv("enthusiasm.csv", header = TRUE)
# Plot the data
plot ( Chapters ~ Enthusiasm, data = enthus +
type = "p", pch = 20 +
main ="Holy Homework!" +
xlab = "Enthusiam units (week number)", xlim = c (0,3) + ylab = "Number of chapters", ylim = c (0,11))
# Fit regression line
abline (lm (Chapters ~ Enthusiasm, data = enthus))
# get equation for limera regression, R-squared and p-value
@jebyrnes
jebyrnes / hubway_dataviz.R
Created November 5, 2012 17:11
Visualize the Hubway Data
##################################################################################################################
######
###### Code to visualize the Hubway Data Set
###### for the Hubway Data Challenge
###### http://hubwaydatachallenge.org/
######
###### Jarrett Byrnes, http://jarrettbyrnes.info
######
###### Last Updated Nov 5, 2012
##################################################################################################################
@jebyrnes
jebyrnes / ma_senate_2012.R
Created November 6, 2012 20:41
MA Senate Projection
#load the excellent methods to query polls
#linked to at http://alandgraf.blogspot.com/2012/11/quick-post-about-getting-and-plotting.html
source("https://raw.github.com/dlinzer/pollstR/master/pollsterAPI.R")
#get the MA Senate Race
datMass <- pollstR(chart="2012-massachusetts-senate-brown-vs-warren",pages="all")
#reshape the data for plotting
library(reshape2)
dm <- melt.data.frame(datMass, id.vars=c("start.date", "N"), measure.vars=c("Warren", "Brown"))