[R-sig-dyn-mod] Altering params for Simecol model at time step

Dougherty, Geoff geoffdougherty at gmail.com
Sun Nov 16 01:48:05 CET 2014


Thomas, 

Thanks for this, it’s really clear and does exactly what I was hoping to accomplish. 

Thanks also for anticipating my next question (multiple inputs). 

Cheers,
GD


On Nov 15, 2014, at 3:14 PM, Thomas Petzoldt <thomas.petzoldt at tu-dresden.de> wrote:

> 
> sir <- new("odeModel",
>  main = function(time, init, parms, inputs, ...){
>    with(as.list(c(init, parms)), {
>      beta <- inputs(time)
>      dS <- -beta*S*I
>      dI <- beta*S*I-I*gamma
>      dR <- I*gamma
>      list(c(dS, dI, dR), beta=beta)
>    })
>  },
>  parms = c(gamma=0.167),
>  times = c(from=0, to=300, by=1),
>  init = c(S=10000000, I=25, R=0),
>  inputs = approxfun(c(0, 60, 300),
>    c(0.18, 0.08, 0.08), method="constant", rule=2),
>  solver = "lsoda"
> )
> 
> 
> sir <- sim(sir)
> plot(sir)


	[[alternative HTML version deleted]]



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