Skip to content

Instantly share code, notes, and snippets.

View jebyrnes's full-sized avatar

Jarrett Byrnes jebyrnes

View GitHub Profile
@jebyrnes
jebyrnes / selectedOutput.Rmd
Created November 26, 2012 20:11
Show only selected pieces of the output from knitr.
# Show selected output
First we redefine the output hook:
```{r setup}
# the default output hook
hook_output = knit_hooks$get('output')
knit_hooks$set(output = function(x, options) {
if (!is.null(n <- options$out.lines)) {
if(length(n)==1) n<-c(n,n)
@jebyrnes
jebyrnes / method_comparison_LRR1.R
Created December 10, 2012 16:18
Compare Methods for Marine Meta-Analysis
#######################################################################################################################################
#
# Compare Different Types of Meta-Analysis Method
# for calculating an effect size from LRR1
#
# Jarrett Byrnes
# Last Updated Dec 9,2012 11am
#
# Changelog
#######################################################################################################################################
@jebyrnes
jebyrnes / sciFundRoundByRound3.R
Created December 15, 2012 16:46
SciFund Round 3 Round by Round Comparison
r3 <- c(0L, 3000L, 1765L, 8645L, 6225L, 805L, 600L, 203L, 115L, 85L,
2700L, 1210L, 3790L, 2210L, 2135L, 610L, 5180L, 840L, 2200L,
410L, 1440L, 3080L, 1280L, 1165L, 4040L, 1110L, 6585L, 3015L,
2651L, 290L, 1990L, 0L, 810L, 5004L, 790L)
r1 <- c(1165L, 1129L, 2835L, 1000L, 5000L, 1120L, 1266L, 2100L, 1330L,
420L, 1070L, 128L, 1120L, 220L, 1075L, 1170L, 825L, 3000L, 1104L,
210L, 122L, 151L, 490L, 4600L, 2483L, 265L, 1565L, 1545L, 4110L,
10171L, 1000L, 1240L, 899L, 1320L, 848L, 605L, 970L, 545L, 1815L,
515L, 5085L, 450L, 755L, 1170L, 250L, 3243L, 1305L, 715L, 711L
@jebyrnes
jebyrnes / lag.R
Last active April 13, 2017 11:44
Methods for generating lagged variables in R
######
# Here are some methods to create a variable
# lagged at t-1. You can see some obvious ways to
# generate arbitrary lags.
#
# See also http://ctszkin.com/2012/03/11/generating-a-laglead-variables/
# for some more tricks.
#
# I wonder why there is no generic function in base for this?
#
@jebyrnes
jebyrnes / sampleAICNet.R
Last active December 16, 2015 04:09
Demo of otu-AIC code
####################################
### Demo of calculating LLs of
### group structures
### And plotting them using the network package
###
### Jarrett Byrnes
### Last updated: 4/11/2013
####################################
source("./getNetworkAIC.R")
@jebyrnes
jebyrnes / MMmultifunc.R
Created August 18, 2013 21:59
Multifunc Michaelis-Menten
library(multifunc)
#A function to get mm coefs
mmCoef <- function(adf){
options(warn=2)
mod <- try(nls(funcMaxed~Vm*Diversity/(K+Diversity), start=list(Vm=1, K=5),
data=adf))
options(warn=0)
@jebyrnes
jebyrnes / scifundGoalAnalysis.R
Last active December 21, 2015 21:09
#SciFund Goal Analyses
source("./sciFundFunctions.r")
library(car)
projects$Round = "1"
projects2$Round = "2"
projects3$Round = "3"
commonCols <- intersect(names(projects2), names(projects3))
#merge just the columns we need for the analysis
cols <- qw(total, Contributors, meanDonation, medianDonation, Goal, Round, Fully.funded., Contributors, Pageviews)
@jebyrnes
jebyrnes / isSamplingReal.R
Created October 8, 2013 14:54
A quick R script I used to convince myself of why our current tests for Sampling effects in BEF research are likely wrong, and result from statistical bias rather than real biology. Thanks to Forest Isbell for hammering the idea home and Marc Hensel for making me explain this clearly.
library(ggplot2)
library(plyr)
###
#let's simulate a diversity experiment with monocultures and polycultures
###
set.seed(2202)
mono <- 8
n <- 8
@jebyrnes
jebyrnes / quantRegLines.R
Created December 4, 2013 15:35
quantRegLines - a function to plot lines from a quantile regression at multiple levels of Tau
###############
# quantRegLines - a function to plot lines from
# a quantile regression at multiple levels of Tau
#
# Jarrett Byrnes
#
# Last Updated Dec 2, 2013
#
# Changelog
###############
@jebyrnes
jebyrnes / changeInFunctionBEF.R
Last active December 30, 2015 06:39
How does a distribution of change in species translate to a distribution of changes in function?
#Michaelis-Menten function with the max function set to 1
#takes h as an argument, the half-saturation
mm <- function(x, h) x/(x+h)
#simple power function
pow <- function(x, p) x^p
#x<-1:100
#plot(x, mm(x), type="l")
#plot(x, pow(x), type="l")