Skip to content

Commit

Permalink
shiver
Browse files Browse the repository at this point in the history
  • Loading branch information
stevencarlislewalker committed Oct 8, 2024
1 parent f5568f6 commit db04030
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 93 deletions.
67 changes: 26 additions & 41 deletions inst/starter_models/shiver/README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ In reality, vaccinations are only partly effective in developing a protective ho

The SHIVER model assumes all individuals can be exposed to the disease, but transmission rates depend on vaccination status. Additionally, individuals with severe infections are hospitalized and assumed to be isolated, before recovering from the disease. Hospital isolation means this portion of infectious individuals no longer contribute to the transmission dynamics.

# Packages Used and Settings

The code in this article uses the following packages.

```{r packages, message=FALSE, warning=FALSE}
library(ggplot2)
library(dplyr)
library(tidyr)
library(macpan2)
library(ggraph)
library(tidygraph)
```

To keep the optimizer from printing too much in this article, we set the `macpan2_verbose` option to `FALSE`.
Expand All @@ -58,6 +58,29 @@ To keep the optimizer from printing too much in this article, we set the `macpan
options(macpan2_verbose = FALSE)
```

# Model Specification

This model has been specified in the `shiver` directory [here](https://github.com/canmod/macpan2/blob/main/inst/starter_models/shiver/tmb.R) and is accessible from the `macpan2` model library (see [Example Models](https://canmod.github.io/macpan2/articles/example_models.html) for details). We can read in the model specification using the `mp_tmb_library` command.
```{r model_spec}
spec = mp_tmb_library(
"starter_models"
, "shiver"
, package = "macpan2"
)
```

This specification can be used to draw the following flow diagrams using code found in the [source for this article](https://github.com/canmod/macpan2/blob/main/inst/starter_models/shiver/README.Rmd). For clarity, we first draw the epidemiological components of the model first, followed by the wastewater shedding component.

```{r diagram, echo = FALSE, fig.height = 3, fig.width = 5}
system.file("utils", "box-drawing.R", package = "macpan2") |> source()
layout = mp_layout_grid(spec
, east = "(infection|progression|recovery)$"
, north = "waning$"
, south = "(hospitalizations|vaccination)$"
)
plot_flow_diagram(layout)
```

# States

| variable | description |
Expand Down Expand Up @@ -86,7 +109,7 @@ The size of the total population is, $N = S + H + I + V + E + R$, and the dise



## Variable Vaccination Rate
# Variable Vaccination Rate

We can implement vaccine constraints by adding more model complexity. Resource limitations create an upper bound on the number of vaccines that can be administered to susceptibles per time step. There is also the constraint that we can only vaccinate, at most, the current number of susceptibles i.e. the vaccination rate can be at most 1. These constraints naturally lead us to consider a variable vaccination rate $\phi(S(t))$, instead of vaccinating a fixed proportion $\phi > 0$ per time step.

Expand Down Expand Up @@ -165,44 +188,6 @@ To convert the Michaelis-Menten curve above to a rate, we divide by $S(t)$.

# Dynamics

We load the model specification from the model library.

```{r model_spec}
spec = mp_tmb_library("starter_models", "shiver", package = "macpan2")
```

```{r}
layout = macpan2:::LayoutMatrixFactors(spec
, east = "(infection|progression|recovery)$"
, north = "waning$"
, south = "(hospitalizations|vaccination)$"
)
plot_flow_diagram(layout)
```

We can draw the flow diagram for this model using the `mp_flow_frame` and the `ggraph` and `tidygraph` packages.

```{r flow_diagram, fig.height=2, fig.width=4}
x_pos = c(S = 1, V = 1, E = 2, I = 3, R = 4, H = 4) / 5
y_pos = c(S = 4, V = 1, E = 4, I = 4, R = 4, H = 1) / 5
node_size = 10
(spec
|> mp_flow_frame(warn_not_dag = FALSE)
|> as_tbl_graph()
|> ggraph('manual', x = x_pos[name], y = y_pos[name])
+ geom_edge_link(
arrow = arrow(length = unit(node_size * 0.3, 'mm'))
, end_cap = circle(node_size / 2, 'mm')
, start_cap = circle(node_size / 2, 'mm')
)
+ geom_node_point(size = node_size, colour = "lightgrey")
+ geom_node_text(aes(label = name), family = "mono")
+ theme_graph(background = NA, plot_margin = margin(0, 0, 0, 0))
+ scale_x_continuous(limits = c(0, 1))
+ scale_y_continuous(limits = c(0, 1))
)
```

$$
\begin{align*}
\frac{dS}{dt} &= -\beta_{S} S\frac{I}{N_{\text{mix}}} - \phi(S) S + \rho V\\
Expand Down
111 changes: 59 additions & 52 deletions inst/starter_models/shiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,37 @@ SHIVER = SEIR + H + V
================
Jennifer Freeman

- [States](#states)
- [Parameters](#parameters)
- [Variable Vaccination Rate](#variable-vaccination-rate)
- [Dynamics](#dynamics)
- [Calibration Example](#calibration-example)
- [Calibration Scenario](#calibration-scenario)
- [Deciding on Defaults](#deciding-on-defaults)
- [Simulating Dynamics](#simulating-dynamics)
- [Estimating Parameters](#estimating-parameters)
- [Re-parameterizing and Introducing
Transformations](#re-parameterizing-and-introducing-transformations)
- [Runge-Kutta 4](#runge-kutta-4)
- [Fitting to Multiple
Trajectories](#fitting-to-multiple-trajectories)
- [Parameter Identifiability](#parameter-identifiability)
- [Model Specification](#model-specification)
- [References](#references)
- <a href="#packages-used-and-settings"
id="toc-packages-used-and-settings">Packages Used and Settings</a>
- <a href="#model-specification" id="toc-model-specification">Model
Specification</a>
- <a href="#states" id="toc-states">States</a>
- <a href="#parameters" id="toc-parameters">Parameters</a>
- <a href="#variable-vaccination-rate"
id="toc-variable-vaccination-rate">Variable Vaccination Rate</a>
- <a href="#dynamics" id="toc-dynamics">Dynamics</a>
- <a href="#calibration-example" id="toc-calibration-example">Calibration
Example</a>
- <a href="#calibration-scenario"
id="toc-calibration-scenario">Calibration Scenario</a>
- <a href="#deciding-on-defaults" id="toc-deciding-on-defaults">Deciding
on Defaults</a>
- <a href="#simulating-dynamics" id="toc-simulating-dynamics">Simulating
Dynamics</a>
- <a href="#estimating-parameters"
id="toc-estimating-parameters">Estimating Parameters</a>
- <a href="#re-parameterizing-and-introducing-transformations"
id="toc-re-parameterizing-and-introducing-transformations">Re-parameterizing
and Introducing Transformations</a>
- <a href="#runge-kutta-4" id="toc-runge-kutta-4">Runge-Kutta 4</a>
- <a href="#fitting-to-multiple-trajectories"
id="toc-fitting-to-multiple-trajectories">Fitting to Multiple
Trajectories</a>
- <a href="#parameter-identifiability"
id="toc-parameter-identifiability">Parameter Identifiability</a>
- <a href="#model-specification-1" id="toc-model-specification-1">Model
Specification</a>
- <a href="#references" id="toc-references">References</a>

This model builds on the basic SEIR model, with two additional
compartments for vaccination and hospitalizations.
Expand Down Expand Up @@ -49,15 +63,15 @@ isolated, before recovering from the disease. Hospital isolation means
this portion of infectious individuals no longer contribute to the
transmission dynamics.

# Packages Used and Settings

The code in this article uses the following packages.

``` r
library(ggplot2)
library(dplyr)
library(tidyr)
library(macpan2)
library(ggraph)
library(tidygraph)
```

To keep the optimizer from printing too much in this article, we set the
Expand All @@ -67,6 +81,31 @@ To keep the optimizer from printing too much in this article, we set the
options(macpan2_verbose = FALSE)
```

# Model Specification

This model has been specified in the `shiver` directory
[here](https://github.com/canmod/macpan2/blob/main/inst/starter_models/shiver/tmb.R)
and is accessible from the `macpan2` model library (see [Example
Models](https://canmod.github.io/macpan2/articles/example_models.html)
for details). We can read in the model specification using the
`mp_tmb_library` command.

``` r
spec = mp_tmb_library(
"starter_models"
, "shiver"
, package = "macpan2"
)
```

This specification can be used to draw the following flow diagrams using
code found in the [source for this
article](https://github.com/canmod/macpan2/blob/main/inst/starter_models/shiver/README.Rmd).
For clarity, we first draw the epidemiological components of the model
first, followed by the wastewater shedding component.

![](./figures/diagram-1.png)<!-- -->

# States

| variable | description |
Expand Down Expand Up @@ -95,7 +134,7 @@ $N_{\text{mix}}=N -H$.
| $\gamma_H$ | per capita recovery rate for hospitalized individuals |
| $\sigma$ | per capita rate at which infected individuals develop severe infections and require hospitalization |

## Variable Vaccination Rate
# Variable Vaccination Rate

We can implement vaccine constraints by adding more model complexity.
Resource limitations create an upper bound on the number of vaccines
Expand Down Expand Up @@ -140,38 +179,6 @@ $S(t)$.

# Dynamics

We first load the model specification from the model library.

``` r
spec = mp_tmb_library("starter_models","shiver", package="macpan2")
```

We can draw the flow diagram for this model using the `mp_flow_frame`
and the `ggraph` and `tidygraph` packages.

``` r
x_pos = c(S = 1, V = 1, E = 2, I = 3, R = 4, H = 4) / 5
y_pos = c(S = 4, V = 1, E = 4, I = 4, R = 4, H = 1) / 5
node_size = 10
(spec
|> mp_flow_frame(warn_not_dag = FALSE)
|> as_tbl_graph()
|> ggraph('manual', x = x_pos[name], y = y_pos[name])
+ geom_edge_link(
arrow = arrow(length = unit(node_size * 0.3, 'mm'))
, end_cap = circle(node_size / 2, 'mm')
, start_cap = circle(node_size / 2, 'mm')
)
+ geom_node_point(size = node_size, colour = "lightgrey")
+ geom_node_text(aes(label = name), family = "mono")
+ theme_graph(background = NA, plot_margin = margin(0, 0, 0, 0))
+ scale_x_continuous(limits = c(0, 1))
+ scale_y_continuous(limits = c(0, 1))
)
```

![](./figures/flow_diagram-1.png)<!-- -->

$$
\begin{align*}
\frac{dS}{dt} &= -\beta_{S} S\frac{I}{N_{\text{mix}}} - \phi(S) S + \rho V\\
Expand Down
Binary file added inst/starter_models/shiver/figures/diagram-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit db04030

Please sign in to comment.