Title: | Generate and Simulate Deterministic Discrete-Time Compartmental Models |
---|---|
Description: | R package to build and simulate deterministic discrete-time compartmental models that can be non-Markov. Length of stay in each compartment can be defined to follow a parametric distribution (d_exponential(), d_gamma(), d_weibull(), d_lognormal()) or a non-parametric distribution (nonparametric()). Other supported types of transition from one compartment to another includes fixed transition (constant()), multinomial (multinomial()), fixed transition probability (transprob()). |
Authors: | Thinh Ong [aut, cph] , Anh Phan [aut, cre], Marc Choisy [aut] , Niels Lohman [ctb], Bjoern Hoehrmann [ctb], Florian Loitsch [ctb], Ingo Berg [ctb] |
Maintainer: | Anh Phan <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0.0.9000 |
Built: | 2024-10-08 05:19:38 UTC |
Source: | https://github.com/thinhong/denim |
Simulate deterministic discrete time model
Imports
Maintainer: Anh Phan [email protected]
Authors:
Thinh Ong [email protected] (ORCID) [copyright holder]
Marc Choisy [email protected] (ORCID)
Other contributors:
Niels Lohman [contributor]
Bjoern Hoehrmann [email protected] [contributor]
Florian Loitsch [contributor]
Ingo Berg [contributor]
Useful links:
Report bugs at https://github.com/thinhong/denim/issues
Define a fixed number of individuals of the left compartment transit to the right compartment at every time step
constant(x)
constant(x)
x |
number of individuals who move from one compartment to another |
a Distribution object for simulator
transitions <- list("S->I" = constant(10))
transitions <- list("S->I" = constant(10))
Discrete exponential distribution
d_exponential(rate)
d_exponential(rate)
rate |
rate parameter of an exponential distribution |
a Distribution object for simulator
transitions <- list("I -> D" = d_exponential(0.3))
transitions <- list("I -> D" = d_exponential(0.3))
Discrete gamma distribution
d_gamma(scale, shape)
d_gamma(scale, shape)
scale |
scale parameter of a gamma distribution |
shape |
shape parameter of a gamma distribution |
a Distribution object for simulator
transitions <- list("S -> I" = d_gamma(1, 5))
transitions <- list("S -> I" = d_gamma(1, 5))
Discrete log-normal distribution
d_lognormal(mu, sigma)
d_lognormal(mu, sigma)
mu |
location parameter or the ln mean |
sigma |
scale parameter or ln standard deviation |
a Distribution object for simulator
transitions <- list("I -> D" = d_lognormal(3, 0.6))
transitions <- list("I -> D" = d_lognormal(3, 0.6))
Discrete Weibull distribution
d_weibull(scale, shape)
d_weibull(scale, shape)
scale |
scale parameter of a Weibull distribution |
shape |
shape parameter of a Weibull distribution |
a Distribution object for simulator
transitions <- list("I -> D" = d_weibull(0.6, 2))
transitions <- list("I -> D" = d_weibull(0.6, 2))
Mathematical expression
mathexpr(expr)
mathexpr(expr)
expr |
User defined mathematial expression. he expression will be processed by muparser library which offers a wide variety of operators. Visit muparser website (https://beltoforion.de/en/muparser/features.php) to see full list of available operators. |
a Distribution object for simulator
transitions <- list("S->I"=mathexpr("beta*S/N")) # definition for parameters in the expression required params <- c(N = 1000, beta = 0.3)
transitions <- list("S->I"=mathexpr("beta*S/N")) # definition for parameters in the expression required params <- c(N = 1000, beta = 0.3)
Define a set of probabilities of transition from one compartment to multiple compartments
"I -> R, D" = multinomial(0.9, 0.1), "I -> R" = d_gamma(3, 2), "I -> D" = d_lognormal(2, 0.5)
is equal to
"0.9 * I -> R" = d_gamma(3, 2), "0.1 * I -> D" = d_lognormal(2, 0.5)
multinomial(...)
multinomial(...)
... |
a vector of probabilities, must add up to 1 |
a Distribution object for simulator
Convert a vector of frequencies, percentages... into a distribution
nonparametric(...)
nonparametric(...)
... |
a vector of values |
a Distribution object for simulator
transitions <- list("S->I"=nonparametric(0.1, 0.2, 0.5, 0.2))
transitions <- list("S->I"=nonparametric(0.1, 0.2, 0.5, 0.2))
Simulation function that call the C++ simulator
sim( transitions, initialValues, parameters = NULL, simulationDuration, timeStep = 1, errorTolerance = 0.001 )
sim( transitions, initialValues, parameters = NULL, simulationDuration, timeStep = 1, errorTolerance = 0.001 )
transitions |
a list of transitions follows this format |
initialValues |
a vector contains the initial values of all compartments defined
in the transitions, follows this format |
parameters |
a vector contains values of any parameters that are not compartments,
usually parameters used in |
simulationDuration |
duration of time to be simulate |
timeStep |
set the output time interval. For example, if |
errorTolerance |
set the threshold so that a cumulative distribution function
can be rounded to 1. For example, if we want a cumulative probability of 0.999 to
be rounded as 1, we set |
a data.frame with class denim
that can be plotted with a plot()
method
transitions <- list( "S -> I" = "beta * S * I / N", "I -> R" = d_gamma(3, 2) ) initialValues <- c( S = 999, I = 1, R = 0 ) parameters <- c( beta = 0.012, N = 1000 ) simulationDuration <- 30 timeStep <- 0.01 mod <- sim(transitions = transitions, initialValues = initialValues, parameters = parameters, simulationDuration = simulationDuration, timeStep = timeStep)
transitions <- list( "S -> I" = "beta * S * I / N", "I -> R" = d_gamma(3, 2) ) initialValues <- c( S = 999, I = 1, R = 0 ) parameters <- c( beta = 0.012, N = 1000 ) simulationDuration <- 30 timeStep <- 0.01 mod <- sim(transitions = transitions, initialValues = initialValues, parameters = parameters, simulationDuration = simulationDuration, timeStep = timeStep)
A fixed percentage of the left compartment transit to the right compartment at every time step
transprob(x)
transprob(x)
x |
a float number between 0 to 1 |
a Distribution object for simulator
transitions <- list("S->I"=transprob(0.8))
transitions <- list("S->I"=transprob(0.8))