[R-sig-dyn-mod] SIR Model
Simeon Lisovski
simeon.lisovski at me.com
Mon Oct 22 12:19:20 CEST 2012
Hi,
thanks Daniel!
Trying to implement the input functions
I realised the real problem. In the example
I did not include for example mortality.
Sorry for that!
This could be simply simulated
as a rate (-my*M).
Using the input functions with M
I am not able to get rid of all Migrants
(due to the decreasing size of M).
With this functions the amount of
the start is important (first subtraction
of Migrants) to end up with 0 Migrants.
Any ideas? Thanks!
Simeon
On 22/10/2012, at 7:27 PM, Daniel Kaschek wrote:
> 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
>
> _______________________________________________
> 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