-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathmpNotesCompartmental.R
More file actions
42 lines (34 loc) · 1.14 KB
/
mpNotesCompartmental.R
File metadata and controls
42 lines (34 loc) · 1.14 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
## flows can be inserted into existing models, to create new ones.
## here is an example inserting waning immunity, where recovered
## individuals flow back to the susceptible compartment. this
## converts the SIR model into a SIRS model.
sirsSpec = (sirSpec
|> mp_tmb_insert(
default = list(omega = 0.06) # waning rate
, expressions = list(mp_per_capita_flow("R", "S", "omega", "waning"))
)
)
## see https://canmod.github.io/macpan2/reference/mp_tmb_insert
## for more information on inserting flows and other expressions
## into model specifications.
## we simulate a trajectory from this SIRS model
sirsContinuousTraj = (sirsSpec
|> mp_rk4()
|> mp_simulator(time_steps = 100, outputs = "I")
|> mp_trajectory()
)
## and combine the trajectories from each model
## into a single data set, and plot it to
## compare the two models.
compareContinuousTraj = bind_rows(
SIR = sirContinuousTraj
, SIRS = sirsContinuousTraj
, .id = "model"
)
(compareContinuousTraj
|> ggplot()
+ aes(time, value, colour = model)
+ geom_line()
)
## what is the effect of waning?
## can you create a plot that clarifies the long-term dynamics of the SIRS model?