-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path240115-fwd-back.Rmd
61 lines (48 loc) · 1.49 KB
/
240115-fwd-back.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
---
title: "Simulating forward and backwards generation intervals"
author: "Oliver Cheng"
date: "2024-01-15"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(deSolve)
source("calculations.R")
source("solver.R")
source("model.R")
source("simulation.R")
source("plots.R")
```
## R Markdown
```{r}
parameters <- c(N = 100000, beta = 0.47857, sigma = 0.4, gamma = 0.17857)
state <- c(S = 99999, E = 1, I = 0, R = 0)
state <- c(S.AB = 99998, S.A = 0, S.B = 0, E.A = 1, E.B = 1, E.AA I = 0, R = 0)
dist <- simulate_seir(state, parameters, 0, 150, stochastic = FALSE)
plot_SEIR(dist, parameters, style="combined")
plot_SEIR(dist, parameters, style="exploded")
plot_SEIR(dist, parameters, style="incidence")
ggplot() +
xlim(0, 50) +
geom_function(fun = dist$F, n = 1000, aes(colour = "F")) +
geom_function(fun = dist$L, n = 1000, aes(colour = "L"))
```
```{r}
times <- seq(0, 200, by=0.1)
gt <- data.frame(time = times)
gt$basic <- basic_mean_gt(dist)
gt$fwd <- sapply(times, \(x) forward_mean_gt(dist, x))
gt$back <- sapply(times, \(x) backward_mean_gt(dist, x))
ggplot(gt, aes(x=time)) +
xlim(0, 200) +
geom_line(aes(y=basic, colour="basic"), linetype="dashed") +
geom_line(aes(y=fwd, colour="forward")) +
geom_line(aes(y=back, colour="backward")) +
geom_line(data=dist$overview,
aes(y = incidence / 1500,
colour="incidence (scaled)"
),
linetype="dashed",
na.rm=TRUE
)
```