The Kermack-McKendrick SIR model is defined as
dS/dt = -beta*N*S
dI/dt = beta*N*S - gamma*I
dR/dt = gamma*I
This model consists of two reactions with the following per capita rates,
transmission: beta
recovery: gamma
Load package
Define parameters
Define initial state vector
Define state-change matrix
Define propensity functions
Run simulations with the Direct method
set.seed(1)
out <- ssa(
x0 = x0,
a = a,
nu = nu,
parms = parms,
tf = tf,
method = ssa.d(),
simName = simName,
verbose = FALSE,
consoleInterval = 1
)
ssa.plot(out, show.title = TRUE, show.legend = FALSE)
Run simulations with the Explict tau-leap method
set.seed(1)
out <- ssa(
x0 = x0,
a = a,
nu = nu,
parms = parms,
tf = tf,
method = ssa.etl(),
simName = simName,
verbose = FALSE,
consoleInterval = 1
)
ssa.plot(out, show.title = TRUE, show.legend = FALSE)
Run simulations with the Binomial tau-leap method
set.seed(2) # for some reason, this does not work with seed = 1
out <- ssa(
x0 = x0,
a = a,
nu = nu,
parms = parms,
tf = tf,
method = ssa.btl(),
simName = simName,
verbose = FALSE,
consoleInterval = 1
)
ssa.plot(out, show.title = TRUE, show.legend = FALSE)
Run simulations with the Optimized tau-leap method