Learn R Programming

SimInf (version 5.1.0)

init: Init a SimInf_mparse object with data

Description

A SimInf_mparse object must be initialised with data to create a SimInf_model that can be used to simulate from the model.

Usage

init(model, u0 = NULL, tspan = NULL, events = NULL, E = NULL,
  N = NULL)

# S4 method for SimInf_mparse init(model, u0 = NULL, tspan = NULL, events = NULL, E = NULL, N = NULL)

Arguments

model

The '>SimInf_mparse object to initialize.

u0

A data.frame (or an object that can be coerced to a data.frame with as.data.frame) with the initial state in each node.

tspan

A vector (length >= 2) of increasing time points where the state of each node is to be returned. Can be either an integer or a Date vector. A Date vector is coerced to a numeric vector as days, where tspan[1] becomes the day of the year of the first year of tspan. The dates are added as names to the numeric vector.

events

A data.frame with the scheduled events. Default is NULL i.e. no scheduled events in the model.

E

Sparse matrix to handle scheduled events, see '>SimInf_events. Default is NULL i.e. no scheduled events in the model.

N

Sparse matrix to handle scheduled events, see '>SimInf_events. Default is NULL i.e. no scheduled events in the model.

Value

a '>SimInf_model object

Examples

Run this code
# NOT RUN {
## Use the model parser to create a 'SimInf_mparse' object that
## expresses a SIR model, where 'b' is the transmission rate and
## 'g' is the recovery rate.
m <- mparse(c("S -> b*S*I/(S+I+R) -> I", "I -> g*I -> R"),
            c("S", "I", "R"), b = 0.16, g = 0.077)

## Initialize a 'SimInf_model' from the 'SimInf_mparse' object
u0 <- data.frame(S = 100, I = 1, R = 0)
model <- init(m, u0 = u0, tspan = 1:100)

## Run and plot the result
result <- run(model, threads = 1, seed = 22)
plot(result)
# }

Run the code above in your browser using DataLab