Skip to content

Instantly share code, notes, and snippets.

@mabarbour
Created November 5, 2012 20:43
Show Gist options
  • Save mabarbour/4020231 to your computer and use it in GitHub Desktop.
Save mabarbour/4020231 to your computer and use it in GitHub Desktop.
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 ######################
### 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.5
Ro <- 0.5
m <- 0.5
a <- 1.6
# Rosenzweig-MacArthur (R-M) consumer-resource (C-R) model that assumes logistic resource growth and a type 2 functional response by the consumer (i.e. consumption rate saturates with resource density)
barbRM <- function(t,y,p) {
R <- y[1]
C <- y[2]
with(as.list(p), {
dR.dt <- r * R * (1 - R / K) - a * C * R / (R + Ro)
dC.dt <- e * a * C * R / (R + Ro) - m * C
return(list(c(dR.dt,dC.dt)))
})
}
Riso <- expression(r/a * (R + Ro) * (1 - R/K)) # solved for isocline separately using pen and paper
RisoStable <- eval(Riso)
p.RM <- c(r = r, e = e, a = a, K = K, Ro = Ro)
Time <- 300
RM1 <- ode(c(0.1,0.1),1:Time, barbRM, p.RM)
plot(R,RisoStable, type = "l", ylab = "C", ylim=0:1)
abline(v=m * Ro / (e * a - m), lty = 2) # abline for consumer isocline was determined using pen and paper. The alternative isocline is C = 0, whichi is uninformative.
# arrows(RM1[-Time,2], RM1[-Time,3], RM1[-1,2], RM1[-1,3], length=0.1); not accurate now but a potential technique to trace stability (from Primer for Ecology with R)
plot(RM1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment