mparseRcpp: Parse custom model using 'SimInf' style markup

View source: R/mparseRcpp.R

mparseRcppR Documentation

Parse custom model using SimInf style markup

Description

Parse custom model using SimInf style markup. Does not have full functionality of mparse. Currently only supports simulations on a single node.

Usage

mparseRcpp(
  transitions = NULL,
  compartments = NULL,
  pars = NULL,
  obsProcess = NULL,
  addVars = NULL,
  stopCrit = NULL,
  tspan = FALSE,
  incidence = FALSE,
  afterTstar = NULL,
  PF = FALSE,
  runFromR = TRUE
)

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").

pars

a character vector containing the names of the parameters.

obsProcess

data.frame determining the observation process. Columns must be in the order: dataNames, dist, p1, p2. dataNames is a character denoting the name of the variable that will be output from the observation process; dist is a character specifying the distribution of the observation process (must be one of "unif", "pois", "norm" or "binom" at the current time); p1 is the first parameter (the lower bound in the case of "unif", the rate in the case of "pois", the mean in the case of "norm" or the size in the case of "binom"); and finally p2 is the second parameter (the upper bound in the case of "unif", NA in the case of "pois", the standard deviation in the case of "norm", and prob in the case of "binom").

addVars

a character vector where the names specify the additional variables to be added to the function call. These can be used to specify variables that can be used for e.g. additional stopping criteria.

stopCrit

A character vector including additional stopping criteria for rejecting simulations early. These will be inserted within if(CRIT){out[0] = 0; return out;} statements within the underlying Rcpp code, which a return value of 0 corresponds to rejecting the simulation. Variables in CRIT must match either those in compartments and/or addVars.

tspan

A logical determining whether to return time series counts or not.

incidence

A logical specifying whether to return incidence curves in addition to counts.

afterTstar

A character containing code to insert after each new event time is generated.

PF

A logical determining whether to compile the code for use in a particle filter.

runFromR

logical determining whether code is to be compiled to run directly in R, or whether to be compiled as an XPtr object for use in Rcpp.

Details

Uses a SimInf style markup to create compartmental state-space written using Rcpp. A helper run function exists to compile and run the model. Another helper function, compileRcpp, can compile the model to produce a function that can be run directly from R, or compiled into an external pointer (using the RcppXPtrUtils package).

Value

An object of class SimBIID_model, which is essentially a list containing elements:

  • code: parsed code to compile;

  • transitions: copy of transitions argument;

  • compartments: copy of compartments argument;

  • pars: copy of pars argument;

  • obsProcess: copy of obsProcess argument;

  • stopCrit: copy of stopCrit argument;

  • addVars: copy of addVars argument;

  • tspan: copy of tspan argument;

  • incidence: copy of incidence argument;

  • afterTstar: copy of afterTstar argument;

  • PF: copy of PF argument;

  • runFromR: copy of runFromR argument.

This can be compiled into an XPtr or function object using compileRcpp().

See Also

run, compileRcpp, print.SimBIID_model

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



tjmckinley/SimBIID documentation built on Sept. 11, 2022, 11:58 a.m.