[R] Predator Prey Models

Berend Hasselman bhh at xs4all.nl
Sun Dec 12 11:25:33 CET 2010



Craig O'Connell-2 wrote:
> 
> Dear R-users,
> 
>    I am currently modifying a previously developed predator prey model and
> was curious if there was a way to add in a disturbance to the model (let's
> say at time t=100).  The disturbance can be the introduction of 40 prey
> (N=40) and 10 predators (Pred = 10).  I would like to see my model go from
> a
> state of equilibrium (up to t = 99), show this disturbance (at t = 100)
> and
> then slowly work its way back to equilibrium.  Does anybody know if this
> could be done?
> 

You can also use package simecol, (imports deSolve), as follows:

library(simecol)

LVmod0D <- new("odeModel",
    main = function(time, state, pars) { 
        with(as.list(c(state,pars)), {
            IngestPred <- rI * N * Pred
            GrowthN    <- rG * N * (1 - N/K)
            MortPred   <- rM * Pred
            
            dN    <- GrowthN - IngestPred
            dPred <- IngestPred * AE - MortPred
            
            return(list(c(dN, dPred)))
        })
    },
    parms = c(rI = 0.1, rG = 0.9, rM = 0.8, AE = 0.9, K = 20),
    times = seq(0, 200, by = 1),
    init = c(N = 20, Pred = 20) ,
    solver="lsoda"
) 
 
# from reply of previous poster
Levents <- list(data=data.frame(var=c("N","Pred"),time=rep(100,2), 
                  value=c(40,10),method=rep("add",2))) 
Levents

lv.sim <- sim(LVmod0D,events=Levents)
lv.out <- out(lv.sim)
lv.out

plot(lv.sim)

I'm not quite sure if the specification of the events is what you need. If I
understood correctly this would be more what you want:

Levents <- list(data=data.frame(var=c("N","Pred"),time=rep(100,2), 
                  value=c(40,10),method=rep("rep",2))) 


best

Berend
-- 
View this message in context: http://r.789695.n4.nabble.com/Predator-Prey-Models-tp3083759p3084165.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list