-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathREADME.Rmd
More file actions
81 lines (59 loc) · 2.09 KB
/
README.Rmd
File metadata and controls
81 lines (59 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-"
)
```
# denim <img src="man/figures/logo.svg" align="right" width="120" />
<!-- badges: start -->
[](https://www.repostatus.org/#active)
[](https://github.com/thinhong/denim/actions/workflows/R-CMD-check.yaml)
[](https://app.codecov.io/gh/thinhong/denim?branch=master)
<!-- badges: end -->
An R package for building and simulating deterministic compartmental models with memory.
## Installation
You can install denim from CRAN with:
``` r
install.packages("denim")
```
Or install the development version of denim from [GitHub](https://github.com/) with:
``` r
# 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:
```{r 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`
```{r}
head(mod)
```
We can plot the output with:
```{r example-plot, dpi=300, fig.width=5}
plot(mod, ylim = c(1, 1000))
```