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? LVmod0D <- 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))) }) } pars <- c(rI = 0.1, rG = 0.9, rM = 0.8, AE = 0.9, K = 20) yini <- c(N = 20, Pred = 20) times <- seq(0, 200, by = 1) y(time=100)<-c(N=10, Pred=5) print(system.time) zout <- as.data.frame(lsoda(yini, y(time=100), times, LVmod0D, pars)) plot(zout[,1],zout[,2], type="l",col="black", ylim=range(0,25), xlab="time",ylab="population") points(zout[,1],zout[,3],type="l",col="red") title(main="prey (black) predator (red)") Thanks much for your help! [[alternative HTML version deleted]]
Craig O'Connell <craigpoconnell <at> gmail.com> writes:> 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?library(deSolve) ?events lsoda(..., events=list(data=data.frame(var=c("N","Pred"),time=rep(100,2), value=c(40,10),method=rep("add",2)))) or something like that ...
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.