Generate and Simulate Deterministic Compartmental Models

R package to build and simulate deterministic compartmental models that can be non-Markovian. 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()).


denim

Project Status: Active – The project has reached a stable, usablestate and is being activelydeveloped. R-CMD-check Codecov testcoverage

An R package for building and simulating deterministic compartmental models with memory.

Installation

You can install denim from CRAN with:

install.packages("denim")

Or install the development version of denim from GitHub with:

# install.packages("devtools")
devtools::install_github("thinhong/denim")

Example

This is a basic example to illustrate the specification of a simple SIR model, which contains three compartments susceptible (S), infected (I) and recovered (R). The recovery probabilities of infected individuals are gamma distributed in this example:

library(denim)

transitions <- denim_dsl({
  S -> I = beta * S * I / N
  I -> R = d_gamma(rate = 1/3, shape = 2)
})

parameters <- c(
  beta = 1.2,
  N = 1000
)

initialValues <- c(
  S = 999, 
  I = 1, 
  R = 0
)

simulationDuration <- 20
timeStep <- 0.01

mod <- sim(transitions = transitions, initialValues = initialValues, 
           parameters = parameters, simulationDuration = simulationDuration, 
           timeStep = timeStep)

The output is a data frame with 4 columns: Time, S, I and R

head(mod)
#>   Time        S        I            R
#> 1 0.00 999.0000 1.000000 0.000000e+00
#> 2 0.01 998.9880 1.011982 5.543225e-06
#> 3 0.02 998.9759 1.024097 2.219016e-05
#> 4 0.03 998.9636 1.036346 5.000038e-05
#> 5 0.04 998.9512 1.048730 8.903457e-05
#> 6 0.05 998.9386 1.061252 1.393545e-04

We can plot the output with:

plot(mod, ylim = c(1, 1000))

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("denim")

1.2.3 by Anh Phan, 9 months ago


https://drthinhong.com/denim/, https://github.com/thinhong/denim


Report a bug at https://github.com/thinhong/denim/issues


Browse source code at https://github.com/cran/denim


Authors: Thinh Ong [aut, cph] , Anh Phan [aut, cre] , Marc Choisy [aut] , Niels Lohman [ctb, cph] (Author of the bundled JSON C++ library) , Bjoern Hoehrmann [ctb, cph] (Author of UTF-8 validation code in the bundled JSON C++ library) , Florian Loitsch [ctb, cph] (Author of the binary to decimal floating-point conversion code in the bundled JSON C++ library) , Ingo Berg [ctb, cph] (Author of the bundled MuParser C++ library)


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports Rcpp, colorspace, rlang, glue

Suggests covr, knitr, rmarkdown, testthat, waldo, xml2, deSolve, tidyverse, DiagrammeR

Linking to Rcpp, testthat


See at CRAN