sir_nsimul: Stochastic SIR model with equal birth and deaths for...

Description Usage Arguments Details Value Examples

View source: R/sir_nsimul.R

Description

A stochastic SIR model with 3 compartments solved using Gillespie’s direct method.

Usage

1
sir_nsimul(x, params, maxstep = 1000, nsims = 5)

Arguments

x

vector of 4 parameters time, S, I and R. time is the initial starting time, S is the Susceptibles, I is the Infecteds and R is the Recovereds.

params

vector of 3 parameters beta, gamma and mu. beta is the transmission rate, gamma is the recovery rate and mu is the per capita death rate, and the population level birth rate.

maxstep

numeric value that indicates the maximum number of transiction between the population. Defaults to 1000.

nsims

numeric value that indicates the number of simulations. Defaults to 5.

Details

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.

Value

data.frameThe 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.

Examples

 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))

NicolasPhysentzides/popdyn documentation built on Sept. 11, 2020, 2:26 p.m.