[R-sig-eco] population simulations in R

Thomas Petzoldt Thomas.Petzoldt at TU-Dresden.de
Sun Jan 13 16:45:43 CET 2013


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))



More information about the R-sig-ecology mailing list