Learn R Programming

SimInf (version 5.0.0)

mparse: Model parser

Description

Describe your model in a logical way in R. mparse creates a '>SimInf_mparse object with your model definition that is ready to be initialised with data and then run.

Usage

mparse(transitions = NULL, compartments = NULL, ...)

Arguments

transitions

character vector containing transitions on the form "X -> ... -> Y". The left (right) side is the initial (final) state and the propensity is written in between the ->-signs. The special symbol @ is reserved for the empty set. For example, transitions = c("S -> k1*S*I -> I", "I -> k2*I -> R") expresses a SIR model.

compartments

contains the names of the involved compartments, for example, compartments = c("S", "I", "R").

...

rate-constants for the model.

Value

'>SimInf_mparse

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