Skip to content

Instantly share code, notes, and snippets.

View aammd's full-sized avatar

Andrew MacDonald aammd

  • Université de Sherbrooke
  • Montreal, Canada
View GitHub Profile
@aammd
aammd / ch2.R
Created November 5, 2012 22:58 — forked from mabarbour/ch2
Code for recreating figures in Chapter 2
######### These are my attempts to incorporate McCann's models into R to help me interpret these food web models ######################
library(deSolve)
### Section 2.2.5
# parameters and state variables for the R-M model
r <- 1.0 # per capita rate of increase in resource
K <- 2.0
e <- 0.7
Ro <- 0.5
@aammd
aammd / mathom.R
Created March 24, 2012 19:31
A simulation of size-dependent diversity effects in experiments that test for diversity
## simulation of experiment
## to test patterns of randomization
## first set up the relationships
## volume is a uniform variable
n.mathoms <- 30
@aammd
aammd / galls.R
Created December 7, 2011 01:58
simulations of gall damage
## a simulation of detecting effect size on gall parasitisim rates
## and occupancy.
## basically ask: how many larvae are in each gall (poisson)
## how many samples do you need to see the difference?
##
#first, a homemade function for the Zero-Inflated Negative Binomial distribution
rzinbinom <- function(n,mu,size,zprob){
ifelse(runif(n)<zprob,0,rnbinom(n,mu=mu,size=size))
}
@aammd
aammd / loopfree.R
Created November 16, 2011 01:34
howtokillaforloop
# by Andrew MacDonald Nov 2011
## please add your own tips and tricks!
## the idea here is to demonstrate how for loops are used
## and then immediately demonstrate how they can be avoided.
## we'll begin by creating a fake dataset.
## This experiment is a 3x3 factorial with 2 replicates of each treatment combination.
## The scientist applied nitrogen and phosphorous to the soil
## then she measured two responses: plant growth and seed production.