[R-sig-dyn-mod] Event Timing question

Melissa Hedges Monk mhedge1 at tigers.lsu.edu
Mon Jun 13 19:09:08 CEST 2011


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)



-- 
Melissa Hedges Monk
Graduate Fellow
Louisiana State University
Department of Oceanography and Coastal Studies
2150 Energy, Coast, and Environment Building
Baton Rouge, LA 70803
225-436-2796 (cell)



More information about the R-sig-dynamic-models mailing list