Description Usage Arguments Details Value Examples
A stochastic SIR model with 3 compartments solved using Gillespie’s direct method.
1 | sir_nsimul(x, params, maxstep = 1000, nsims = 5)
|
x |
|
params |
|
maxstep |
|
nsims |
|
S
,I
,R
must be positive and S + I + R = N
. N
is the whole population. Every simulation stops when there are no Infecteds or when the maximum number of steps is reached.
data.frame
The data.frame contains 5 columns. Second, third,fourth and fifth are the arguments of the input vector x
. The first column indicates the specific number of the simulation. The column takes (.n
) values from 1 up to nsims
increasing by 1.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | library('plyr')
set.seed(0)
nsims <- 8
xstart <- c(time=0,S=595,I=5,R=0) #initial conditions
params <- c(mu=0.015,beta=20,gamma=13) #parameters
res <- sir_nsimul(x = xstart, params = params, nsims = nsims)
par(mfrow=c(3,1), mar=c(2,4,1,1))
plot(S~time,data=res,type='n')
d_ply(res,".n",function(x)lines(S~time,data=x,col=.n))
plot(I~time,data=res,type='n')
d_ply(res,".n",function(x)lines(I~time,data=x,col=.n))
plot(R~time,data=res,type='n')
d_ply(res,".n",function(x)lines(R~time,data=x,col=.n))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.