Build a demographic process model (ODE or SDE)
Source:R/treeSimulatorCpp2.R
build.demographic.process.Rd
A model is constructed by supplying birth rates, migration rates, and death rates. The model can be used to simulate demographic histories or as an input to coalescent simulation or likelihood calculation. The demographic model can be created using ordinary differential equations (ODEs) or stochastic differential equations (SDEs)
Usage
build.demographic.process(
births,
nonDemeDynamics = NA,
migrations = NA,
deaths = NA,
parameterNames = c(),
rcpp = TRUE,
sde = FALSE
)
Arguments
- births
A named character vector or matrix of mathematical expressions that describe model birth rates. Names correspond to each deme. If there is more than one deme, a matrix must be supplied describing birth rates between each pair of demes. Either R or C code can be supplied (see rcpp option).
- nonDemeDynamics
A named character vector of mathematical expressions that describe rate of change for dynamic variables which are not demes; for example: an equation for the number susceptible in an SIR model.
- migrations
A named character vector or matrix of mathematical expressions that describe model migration rates. Names correspond to each deme. If there is more than one deme, a matrix must be supplied describing migration rates between each pair of demes. Either R or C code can be supplied (see rcpp option).
- deaths
A named character vector of mathematical expressions that describe death rates in each deme.
- parameterNames
A character vector providing the names of static parameters used in the model.
- rcpp
If TRUE, the expressions are interpreted as C code using the Rcpp package.
- sde
If TRUE, a stochastic differential equation model is constructed; if FALSE, an ordinary differential equation model is constructed.
Value
An object of class demographic.process
, which is a function
that can be used to simulate the model. The model can also be used as an
input to tree simulation or likelihood calculation.
Examples
# A simple exponential growth model with birth rates beta, and death rates gamma:
# I is the number of infected individuals.
dm <- build.demographic.process(births=c(I = 'parms$beta * I'),
deaths = c(I = 'parms$gamma * I'),
parameterNames=c('beta', 'gamma'),
rcpp=FALSE,
sde = TRUE)
# Do a simulation and plot the trajectory:
show.demographic.process(dm,
theta = list(beta = 1.5, gamma = 1),
x0 = c(I = 1),
t0 = 0,
t1 = 10)