[R-sig-dyn-mod] SIR Model

Daniel Kaschek daniel.kaschek at physik.uni-freiburg.de
Mon Oct 22 10:27:32 CEST 2012


Hi Simeon,

you could define input functions

arrival <- function(t, tarrival, timespan, amount) {

	amount*dnorm(t, tarrival, timespan)

}

and analogously departure(). Then in your function mod, you would have

dM <- arrival(t, tarrival, timespan, amountComing) - departure(t,
tdeparture, timespan, amountLeaving)

tarrival, timespan, etc. are parameters in the parms vector.

You have to pay attention with the departure. In the above construction
M can become negative. This can be avoided by multiplying departure(t)
with M, e.g. dM = arrival - M*departure. In this case amountLeaving has
no longer the meaning of the number of persons leaving but reflects more
the velocity of the decay of M.

Hope this helps.

Best,
Daniel.



On Mon, 2012-10-22 at 19:09 +1100, Simeon Lisovski wrote:
> Hi,
>  the following model (realised with deSolve) 
> includes four different but connected differential
> equations. This example is a simplification
> of an disease infection model (S=Susceptible, 
> I=Infected, R=Recovered, M=Migrants):
> 
> library(deSolve)
> 
> mod <- function(t, x, parms){
> 	with(as.list(c(x,parms)),{
> 	
> 	dS <- -b*I*M*S - h*I
> 	dI <-  b*I*M*S + h*I - r*I
> 	dR <-          r*I
> 	
> 	dM <- 0
> 	
> 	res <- c(dS, dI, dR, dM)
> 	list(res)
> 	})
> }
> 
> eventdat <- data.frame(var = c("M", "M"),
>                        time = c(100, 200) ,
>                        value = c(200, 0),
>                        method = c("add", "rep"))
> 
> 
> 
> xstart <- c(S=500, I=10, R=0, M=0)
> times  <- 1:365
> parms  <- c(
> 		b=0.0005,
> 		r=0.005,
> 		h=0.0005
> )
> 
> tmp <- ode(xstart, times, mod, parms, event=list(data=eventdat))
> plot(tmp)
> 
> 
> 
> Migrants are leaving and entering
> the system and I used events for both processes, however 
> this is not really biological. Both events would better
> reflect nature if they are following a sigmoidal pattern.
> 
> I tried different ways of creating a rate following the area
> under a normal distribution which somehow works but
> could never delete all Migrants at the end of the year
> (for obvious reasons).
> 
> Ideally, I would like to give the start and the end of the
> process as parameters (arrival or departure and the amount of
> Individuals entering the system).
> 
> Any ideas are very much appreciated!
> Simeon
> 
> 	[[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