[R-sig-dyn-mod] Initial value for additive events

John Harrold john.m.harrold at gmail.com
Sat Apr 18 01:24:24 CEST 2015


Hello,

When I have an additive event that occurs at the initial sample time the
state receiving the value has a value of the specified initial condition.
For example see the code below. I understand that the initial condition is
set to zero, but I guess from my perspective adding a value at time zero
should change that initial condition. This is important for me because
bolus injections (impulse functions) into states with a value of zero is
pretty common for my work. It makes plotting things on a log scale
difficult when a zero value always exists. It also looks kind of silly to
have the system start at zero when the injection was supposed to occur.

So my question is more about how to deal with this if my goal is to remove
this point? One option is to automatically sample at a really small value
(SV = 250*.Machine$double.eps) then set the value of the state receiving
the event at time zero to the value at time SV. It's messy but doable.
Anyway I was wondering if there were any thoughts?

Thanks
John

<CODE>
rm(list=ls())
library("deSolve")
library("ggplot2")
yini <- c(v1=0)
times <-seq(0,10, by=.01)
f1 <- function  (t, y, parms) {
   ydot <- vector(len = 1)
   ydot[1] <- - 0.1*y[1]
 return(list(ydot))
}
eventdat <- data.frame(var    = c("v1", "v1", "v1", "v1"),
                       time   = c(0, 1, 2, 3),
                       value  = c(1, 1, 1, 1),
                       method = c("add", "add", "add", "add"))
out <- ode(func=f1,
           y=yini,
           times = times,
          parms = NULL,
          events = list(data = eventdat))
plot(out, type="l", lwd=2)
</CODE>

	[[alternative HTML version deleted]]



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