Skip to content

[R-sig-dyn-mod] Timing of Events question

1 message · Melissa Hedges Monk

#
Hello
    I'm having trouble understanding where and how in my code to use
either cleanEventTimes or nearestEvent to match the event times with
the integration steps.  I would like to trigger the event function at
whole integer numbers from 0 to 200, while integrating from 0->200
with 2000 time steps.  The pertinent portion of my R code is below.
Thank you in advance for your help!

Cheers
Melissa

#derivative
lvm <- function(t,x,parms){
        dx <- (r + a %*% x) * x
        list(dx)
               }

# integration function
n.integrate <- function(time=time,init.x= init.x,model=model){

        t.out <- seq(time$start,time$end,length=time$steps)
        times = seq(0,200,1)
           as.data.frame(lsoda(init.x,t.out,model,parms=parms,events =
list(func = eventfun, time = seq(0,200,1))))
           }

#event function; event=change in environmental variability
  eventfun <- function(t, y, parms){
         with(as.list(y),{
          colnum = which(colnames(env.fmort) == t)
            test1 = env.fmort[ , colnum]
            r <- r + test1
            return(c(r))
            })
            }

###########################
# MAIN PROGRAM
###########################
 steps1= 2000
 parms <- c(0)
 time<- list(start=0,end=200,steps=steps1)
# integrate lvm model
 out <-n.integrate(time=time,init.x=init.x,model=lvm)