[R-sig-dyn-mod] dede solve issue
Karline Soetaert
Karline.Soetaert at nioz.nl
Wed May 3 14:59:18 CEST 2017
Hi Emily, I think it is a matter of both your output times (from 0 to 100) which are smaller than the tau you impose (200) and the parameter values. For instance if I change your model to this - I do get differences based on tau:
library(deSolve)
SIRlag<-function(t,y,p,tau){
S<-y[1]; I<-y[2]
B<-p[1]
g<-p[2]
a1<-p[3]
a2<-p[4]
mm<-p[5]
b<-p[6]
tlag <- t - tau
if (tlag <= 0)
ylag <- 0.5
else
ylag <- lagvalue(tlag)
dS.dt <- (1-min((a1+a2*ylag[1]), mm))*b*(S+I)-((B*S*I)/(S+I))-b*S
dI.dt <- ((B*S*I)/(S+I)) - (g*I) - (b*I)
return(list(c(dS.dt, dI.dt), ylag[1], ylag[2])) # also returned ylag
}
times<-seq(0,100, by=1)
outSIR<-dede(y=c(5000,1),times=times, func=SIRlag, parms=c(1.2,0.07,0.1,0.18,0.4,0.4), tau=20) # tau made smaller and values of some parameters changed
outSIR2<-dede(y=c(5000,1),times=times, func=SIRlag, parms=c(1.2,0.07,0.1,0.18,0.4,0.4), tau=10)
plot(outSIR, outSIR2)
Hope this helps,
Karline
-----Original Message-----
From: R-sig-dynamic-models [mailto:r-sig-dynamic-models-bounces at r-project.org] On Behalf Of Emily Vachon
Sent: donderdag 27 april 2017 16:44
To: r-sig-dynamic-models at r-project.org
Subject: [R-sig-dyn-mod] dede solve issue
Hi Everyone,
I am trying to run an SIR disease model with a time lag. The time lag is represented by tau. I am using Dede solve within DeSolve, but something is happening where the tau is not changing the output. It has absolutely no bearing on the graph I get. Clearly there's an issue somewhere in my code.
This is the code:
library(deSolve)
SIRlag<-function(t,y,p,tau){
S<-y[1]; I<-y[2]
B<-p[1]
g<-p[2]
a1<-p[3]
a2<-p[4]
mm<-p[5]
b<-p[6]
tlag <- t - tau
if (tlag <= 0)
ylag <- 0.5
else
ylag <- lagvalue(tlag)
dS.dt <- (1-min((a1+a2*ylag[1]), mm))*b*(S+I)-((B*S*I)/(S+I))-b*S
dI.dt <- ((B*S*I)/(S+I)) - (g*I) - (b*I)
return(list(c(dS.dt, dI.dt)))
}
times<-seq(0,100, by=1)
outSIR<-dede(y=c(5000,1),times=times, func=SIRlag, parms=c(1.2,0.07,0.1,0.018,0.4,0.00004), tau=200) matplot(outSIR[,1],outSIR[,2:3], type="l", xlab="time", ylab="populations")
Does anyone see any obvious issues?
Thank you,
[[alternative HTML version deleted]]
_______________________________________________
R-sig-dynamic-models mailing list
R-sig-dynamic-models at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-dynamic-models
More information about the R-sig-dynamic-models
mailing list