-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
137 lines (102 loc) · 4.06 KB
/
README.Rmd
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
---
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-",
out.width = "100%"
)
```
# tti
<!-- badges: start -->
[![Travis build status](https://travis-ci.org/HopkinsIDD/tti.svg?branch=master)](https://travis-ci.org/HopkinsIDD/tti)
[![Codecov test coverage](https://codecov.io/gh/HopkinsIDD/tti/branch/master/graph/badge.svg)](https://codecov.io/gh/HopkinsIDD/tti?branch=master)
<!-- badges: end -->
The goal of tti is to facilitate the recursive calculation of infection proportions for the test-trace-isolate process.
## Installation
You can install the development version of tti from GitHub with:
``` r
devtools::install_github("HopkinsIDD/tti")
```
## Examples
```{r}
library(tti)
```
The `get_dqc_equilibrium()` function will iterate through the detected-quarantine-community vectors until "equilibrium" is met, as specified by the `tolerance` parameter. For example, here we start with 80% symptomatic in the community and 20% asymptomatic in the community.
```{r}
dqc <- get_dqc_equilibrium(init = c(Ds = 0, Da = 0, Qcds = 0, Qhds = 0,
Qcda = 0, Qhda = 0, Qq = 0, Cs = 0.8,
Ca = 0.2))
dqc
```
From this, we can calculate the proportion quarantined using the `get_prop_quarantined()` function.
```{r}
get_prop_quarantined(dqc)
```
We can then calculate the $R_{effective}$ under this scenario.
```{r}
get_r_effective(dqc)
```
The function `get_proportions_df()` will generate a data frame with four columns:
* `t`: the time (iteration)
* `prop_infected`: The proportion infected
* `r_effective`: The effective R value
* `category`: The category
For example, to run the recursive function over 10 time points, we would run the following.
```{r}
d <- get_proportions_df(duration = 10)
d
```
```{r fig-example, message = FALSE, warning = FALSE}
library(ggplot2)
ggplot(d, aes(x = t, y = prop_infected, color = category)) +
geom_line() +
scale_y_continuous("Proportion of Infected")
```
We can then calculate the effective $R$ after each iteration.
```{r, message = FALSE, warning = FALSE}
library(dplyr)
r <- d %>%
distinct(t, r_effective)
r
```
```{r eff-r}
ggplot(r, aes(x = t, y = r_effective)) +
geom_line() +
scale_y_continuous("Effective R")
```
We can also look at the $R_{effective}$ over a variety of parameters using the `get_r_effective_df()` function. This can take parameters as either single number scalars or vectors of parameters to try. For example, if we wanted to look at how $R$ is affected by varying `t_ds` between 1 and 14 and `rho_s` values of 0.05, 0.25, and 0.5, we would run the following.
```{r}
d <- get_r_effective_df(t_ds = 1:14,
rho_s = c(0.05, 0.25, 0.5))
d
```
This gives us a data frame with 18 columns, the first being the $R_{effective}$ and the subsequent columns detailing the parameters. Notice here there are 52 rows, because we had 52 combinations of `t_ds` and `rho_s` that we provided.
```{r eff-r-sim}
ggplot(d, aes(x = t_ds, y = r_effective, color = factor(rho_s))) +
geom_line() +
scale_y_continuous("Effective R") +
scale_x_continuous("Delay (symptomatic case detection and isolation)") +
scale_color_discrete("P(detected | symptomatic)")
```
## Base functions
We also include some low-level functions that take any sized compartment vector along with a conformable infection matrix and detection matrix. These are meant for more experienced users familiar with the underlying mathematical model.
```{r}
infect <- matrix(c(2.5, 0, 0,
0, 1, 0,
0, 0, 2.5), nrow = 3, byrow = TRUE)
detect <- matrix(c(0.1, 0.5, 0.4,
0.02, 0.9, 0.08,
0.2, 0, 0.8), nrow = 3, byrow = TRUE)
dqc <- get_dqc_equilibrium_base(init = c(0, 0, 1),
infect = infect,
detect = detect
)
dqc
```
```{r}
get_r_effective_base(dqc, infect)
```