Skip to content

population simulations in R

5 messages · Peter Houk, Duncan Golicher, Roman Luštrik +1 more

#
Hello Peter,

It should be easy to adapt this to your needs.

http://duncanjg.wordpress.com/2008/03/12/disturbance-and-the-lotka-volterra-competition-model/

All the best,

Duncan
On Sun, Jan 13, 2013 at 11:40 AM, Peter Houk <peterhouk at gmail.com> wrote:

  
    
#
Hi,

I would do it like follows and I don't expect that the for loop should 
be a performance problem here ;-)

Tomas P.


logistic <- function(x0, r, t) {
   xx <- matrix(0, nrow = length(t), ncol = length(x0))
   xx[1, ] <- x0
   for (i in t)  x0 <- xx[i, ] <- x0 + r * x0 * (1 - x0)
   xx
}


nruns <- 100
time  <- seq(1, 15)
r     <- runif(nruns, 0.8, 1.1)
x0    <- rep(0.01, nruns)

system.time(
   xx <- logistic(x0, r, time)
)

matplot(time, xx, type = "l", pch = ".", ylim = c(0,2))