mparse {SimInf} | R Documentation

## Model parser to define new models to run in `SimInf`

### Description

Describe your model in a logical way in R. `mparse` creates a `SimInf_model` object with your model definition that is ready to `run`.

### Usage

    mparse(transitions = NULL, compartments = NULL, ldata = NULL,
      gdata = NULL, u0 = NULL, v0 = NULL, tspan = NULL,
      events = NULL, E = NULL, N = NULL, pts_fun = 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")`.

`ldata`

optional data for the nodes. Can be specified either as a numeric matrix where column `ldata[, j]` contains the local data vector for the node `j` or as a `data.frame` with one row per node. If it's specified as a matrix, it must have row names to identify the parameters in the transitions. If it's specified as a data.frame, each column is one parameter. The local data vector is passed as an argument to the transition rate functions and the post time step function.

`gdata` | optional data that are common to all nodes in the model. Can be specified either as a named numeric vector or as as a one-row data.frame. The names are used to identify the parameters in the transitions. The global data vector is passed as an argument to the transition rate functions and the post time step function.
`u0` | A `data.frame` (or an object that can be coerced to a `data.frame` with `as.data.frame`) with the initial state i.e. the number of individuals in each compartment in each node when the simulation starts..

`v0`

optional data with the initial continuous state in each node. Can be specified either as a `data.frame` with one row per node or as a numeric matrix where column `v0[, j]` contains the initial state vector for the node `j`. If `v0` is specified as a `data.frame`, each column is one parameter. If `v0` is specified as a matrix, the row names identify the parameters. The 'v' vector is passed as an argument to the transition rate functions and the post time step function. The continuous state can be updated in the post time step function.

`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` | matrix to handle scheduled events, see `SimInf_events`. Default is `NULL` i.e. no scheduled events in the model.
`N` | matrix to handle scheduled events, see `SimInf_events`. Default is `NULL` i.e. no scheduled events in the model.
`pts_fun` | optional character vector with C code for the post time step function. The C code should contain only the body of the function i.e. the code between the opening and closing curly brackets.

### Value

a `SimInf_model` object

### Examples

    ## Not run:
    ## Use the model parser to create a 'SimInf_model' object that
    ## expresses a SIR model, where 'b' is the transmission rate and
    ## 'g' is the recovery rate.
    model  <- mparse(transitions = c("S -> b*S*I/(S+I+R) -> I",
                                     "I -> g*I -> R"),
                     compartments = c("S", "I", "R"),
                     gdata = c(b = 0.16, g = 0.077),
                     u0 = data.frame(S = 100, I = 1, R = 0),
                     tspan = 1:100)

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

    ## End(Not run)

[Package SimInf version 6.3.0 Index]