run {SimBIID}R Documentation

Runs SimBIID_model object

Description

Wrapper function that compiles (if necessary) and runs a SimBIID_model object. Returns results in a user-friendly manner as a SimBIID_run object, for which print() and plot() generics are provided.

Usage

run(
  model,
  pars,
  tstart,
  tstop,
  u,
  tspan,
  nrep = 1,
  parallel = FALSE,
  mc.cores = NA
)

Arguments

model

An object of class SimBIID_model.

pars

A named vector of parameters.

tstart

The time at which to start the simulation.

tstop

The time at which to stop the simulation.

u

A named vector of initial states.

tspan

A numeric vector containing the times at which to save the states of the system.

nrep

Specifies the number of simulations to run.

parallel

A logical determining whether to use parallel processing or not.

mc.cores

Number of cores to use if using parallel processing.

Value

An object of class SimBIID_run, essentially a list containing elements:

See Also

mparseRcpp, print.SimBIID_runs, plot.SimBIID_runs

Examples


## set up SIR simulation model
transitions <- c(
    "S -> beta * S * I -> I", 
    "I -> gamma * I -> R"
)
compartments <- c("S", "I", "R")
pars <- c("beta", "gamma")
model <- mparseRcpp(
    transitions = transitions, 
    compartments = compartments,
    pars = pars
)

## compile and run model
sims <- run(
    model = model,
    pars = c(beta = 0.001, gamma = 0.1),
    tstart = 0,
    tstop = 100,
    u = c(S = 119, I = 1, R = 0)
)
sims

## add tspan option to return
## time series counts at different
## time points
model <- mparseRcpp(
    transitions = transitions, 
    compartments = compartments,
    pars = pars,
    tspan = TRUE
)
sims <- run(
    model = model,
    pars = c(beta = 0.001, gamma = 0.1),
    tstart = 0,
    tstop = 100,
    u = c(S = 119, I = 1, R = 0),
    tspan = seq(1, 100, length.out = 10)
)
sims

## run 100 replicate simulations and
## plot outputs
sims <- run(
    model = model,
    pars = c(beta = 0.001, gamma = 0.1),
    tstart = 0,
    tstop = 100,
    u = c(S = 119, I = 1, R = 0),
    tspan = seq(1, 100, length.out = 10),
    nrep = 100
)
sims
plot(sims)


[Package SimBIID version 0.2.1 Index]