Skip to content

Commit

Permalink
differences for PR #55
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Nov 9, 2023
1 parent d193ef8 commit 9930960
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 85 deletions.
5 changes: 2 additions & 3 deletions compare-interventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@ The Vacamole model is a deterministic model based on a system of ODEs in [Ainsli

The diagram below describes the flow of individuals through the different compartments.

<!--html_preserve--><div class="grViz html-widget html-fill-item-overflow-hidden html-fill-item" id="htmlwidget-ca6af240f574fa8839fc" style="width:504px;height:504px;"></div>
<script type="application/json" data-for="htmlwidget-ca6af240f574fa8839fc">{"x":{"diagram":"digraph{\n # graph statement\n #################\n graph [layout = dot,\n rankdir = LR,\n overlap = true,\n fontsize = 10]\n\n # nodes\n #######\n node [shape = square,\n fixedsize = true\n width = 1.3]\n\n S\n E\n Ev [label = <E<FONT POINT-SIZE=\"8\"><SUB>V<\/SUB><\/FONT>>, style = filled, fillcolour = \"gray\"]\n I\n Iv [label = <I<FONT POINT-SIZE=\"8\"><SUB>V<\/SUB><\/FONT>>, style = filled, fillcolour = \"gray\"]\n H\n Hv [label = <H<FONT POINT-SIZE=\"8\"><SUB>V<\/SUB><\/FONT>>, style = filled, fillcolour = \"gray\"]\n D\n R\n V1 [label = <V<FONT POINT-SIZE=\"8\"><SUB>1<\/SUB><\/FONT>>, style = filled, fillcolour = \"gray\"]\n V2 [label = <V<FONT POINT-SIZE=\"8\"><SUB>2<\/SUB><\/FONT>>, style = filled, fillcolour = \"gray\"]\n\n\n # edges\n #######\n S -> E [label = \" infection (&beta;) \"]\n S -> V1 [label = \" vaccination (&nu;1)\"]\n V1 -> E [label = \" infection (&beta;)\"]\n V1 -> V2 [label = \" vaccination\n(second dose) (&nu;2)\"]\n V2 -> Ev [label = \" infection (&beta;)\"]\n Ev -> Iv [label = \" onset of \ninfectiousness (&alpha;) \"]\n E -> I [label = \" onset of \ninfectiousness (&alpha;) \"]\n I -> H [label = \" hospitalisation (&eta;)\"]\n Iv -> Hv [label = < hospitalisation (&eta;<FONT POINT-SIZE=\"8\"><SUB>V<\/SUB><\/FONT>)>]\n I -> D [label = \" death (&omega;)\"]\n I -> R [label = \" recovery (&gamma;)\"]\n Iv -> D [label = < death (&omega;<FONT POINT-SIZE=\"8\"><SUB>V<\/SUB><\/FONT>)>]\n Iv -> R [label = \" recovery (&gamma;)\"]\n Hv -> D [label = < death (&omega;<FONT POINT-SIZE=\"8\"><SUB>V<\/SUB><\/FONT>)>]\n Hv -> R [label = \" recovery (&gamma;)\"]\n H -> D [label = \" death (&omega;)\"]\n H -> R [label = \" recovery (&gamma;)\"]\n\n subgraph {\n rank = same; S; V1;V2;\n }\n}","config":{"engine":"dot","options":null}},"evals":[],"jsHooks":[]}</script><!--/html_preserve-->
<img src="fig/compare-interventions-rendered-unnamed-chunk-1-1.png" style="display: block; margin: auto;" />

See `?epidemics::epidemic_vacamole` for detail on how to run the model.
See `?epidemics::model_vacamole_cpp` for detail on how to run the model.

## Comparing scenarios

Expand Down
Binary file modified fig/simulating-transmission-rendered-plot-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions md5sum.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"config.yaml" "ba8182fefb4b3a156058872157fb2d7d" "site/built/config.yaml" "2023-10-31"
"index.md" "adfca1a79e0106ee8b3f7731d0678b59" "site/built/index.md" "2023-11-09"
"links.md" "8184cf4149eafbf03ce8da8ff0778c14" "site/built/links.md" "2023-10-31"
"episodes/simulating-transmission.Rmd" "a09170bca196d6a7ba714ddf159e2e2a" "site/built/simulating-transmission.md" "2023-11-09"
"episodes/model-choices.Rmd" "4e9de6f75c88cfbe0c265a55ea61345f" "site/built/model-choices.md" "2023-11-09"
"episodes/modelling-interventions.Rmd" "dff06995ab8d9c4b7b73f162dbf52590" "site/built/modelling-interventions.md" "2023-11-09"
"episodes/compare-interventions.Rmd" "32da6fa2116d62a3d783e397a2908c15" "site/built/compare-interventions.md" "2023-11-09"
"episodes/simulating-transmission.Rmd" "c9f03af77dc859f03b9cd57c9e76a12b" "site/built/simulating-transmission.md" "2023-11-09"
"episodes/model-choices.Rmd" "e1aa902ded8b7786e9fba71032f3c7b1" "site/built/model-choices.md" "2023-11-09"
"episodes/modelling-interventions.Rmd" "0c2b8a23920ad50e6cde1bd0eadb0859" "site/built/modelling-interventions.md" "2023-11-09"
"episodes/compare-interventions.Rmd" "78123d2140fbe6488cd295eba3066fcd" "site/built/compare-interventions.md" "2023-11-09"
"instructors/instructor-notes.md" "ca3834a1b0f9e70c4702aa7a367a6bb5" "site/built/instructor-notes.md" "2023-10-31"
"learners/reference.md" "334277298b83c92dd98c28de895d43cb" "site/built/reference.md" "2023-11-09"
"learners/setup.md" "b3c6bfa13fd687f926bb1a3e772a2516" "site/built/setup.md" "2023-10-31"
Expand Down
16 changes: 7 additions & 9 deletions model-choices.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Finally, interventions such as vaccination may be of interest. A model may or ma
### Available models

The R package `epidemics` contains functions to run existing models.
For details on the models that are available, see the package [vignettes](https://epiverse-trace.github.io/epidemics/articles). To learn how to run the models in R, read the documentation using `?epidemics::epidemic_ebola`. Remember to use the 'Check model equation' questions to help your understanding of an existing model.
For details on the models that are available, see the package [vignettes](https://epiverse-trace.github.io/epidemics/articles). To learn how to run the models in R, read the documentation using `?epidemics::model_ebola_r`. Remember to use the 'Check model equation' questions to help your understanding of an existing model.

::::::::::::::::::::::::::::::::::::: checklist
### Check model equations
Expand All @@ -85,9 +85,9 @@ You have been asked to explore the variation in numbers of infected individuals

Which of the following models would be an appropriate choice for this task:

+ `epidemic_default`
+ `model_default_cpp()`

+ `epidemic_ebola`
+ `model_ebola_r()`

::::::::::::::::: hint

Expand Down Expand Up @@ -118,23 +118,21 @@ Consider the following questions:
+ What is the outcome of interest? **Number of infections**
+ Will any interventions be modelled? **No**

#### `epidemic_default`
#### `model_default_cpp()`

A deterministic SEIR model with age specific direct transmission.

<!--html_preserve--><div class="grViz html-widget html-fill-item-overflow-hidden html-fill-item" id="htmlwidget-133f080a5048e6f8c46b" style="width:504px;height:504px;"></div>
<script type="application/json" data-for="htmlwidget-133f080a5048e6f8c46b">{"x":{"diagram":"digraph {\n # graph statement\n #################\n graph [layout = dot,\n rankdir = LR,\n overlap = true,\n fontsize = 10]\n # nodes\n #######\n node [shape = square,\n fixedsize = true,\n width = 1.3]\n S\n E\n I\n R\n\n # edges\n #######\n S -> E [label = \" infection\"]\n E -> I [label = \" onset of \ninfectiousness\"]\n I -> R [label = \" recovery\"]\n}","config":{"engine":"dot","options":null}},"evals":[],"jsHooks":[]}</script><!--/html_preserve-->
<img src="fig/model-choices-rendered-diagram-1.png" style="display: block; margin: auto;" />


The model is capable of predicting an Ebola type outbreak, but as the model is deterministic, we are not able to explore stochastic variation in the early stages of the outbreak.


#### `epidemic_ebola`
#### `model_ebola_r()`

A stochastic SEIHFR (Susceptible, Exposed, Infectious, Hospitalised, Funeral, Removed) model that was developed specifically for infection with Ebola.

<!--html_preserve--><div class="grViz html-widget html-fill-item-overflow-hidden html-fill-item" id="htmlwidget-2bce1f548a563a09141f" style="width:504px;height:504px;"></div>
<script type="application/json" data-for="htmlwidget-2bce1f548a563a09141f">{"x":{"diagram":"digraph {\n\n # graph statement\n #################\n graph [layout = dot,\n rankdir = LR,\n overlap = true,\n fontsize = 10]\n\n # nodes\n #######\n node [shape = square,\n fixedsize = true\n width = 1.3]\n\n S\n E\n I\n H\n F\n R\n\n # edges\n #######\n S -> E [label = \" infection \"]\n E -> I [label = \" onset of \ninfectiousness\"]\n I -> F [label = \" death \n(funeral) \"]\n F -> R [label = \" safe burial\"]\n I -> H [label = \" hospitalisation\"]\n H -> R [label = \" recovery or \nsafe burial\"]\n\n subgraph {\n rank = same; I; F;\n }\n subgraph {\n rank = same; H; R;\n }\n}","config":{"engine":"dot","options":null}},"evals":[],"jsHooks":[]}</script><!--/html_preserve-->
<img src="fig/model-choices-rendered-unnamed-chunk-1-1.png" style="display: block; margin: auto;" />



Expand Down
41 changes: 8 additions & 33 deletions modelling-interventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ In mathematical modelling, we must make assumptions about how NPIs will affect t

We want to investigate the effect of school closures on reducing the number of individuals infectious with COVID-19 through time. We assume that a school closure will reduce the frequency of contacts within and between different age groups.

Using an SEIR model (`epidemic_default()` in the R package `{epidemics}`) we set $R_0 = 2.7$, preinfectious period $= 4$ and the infectious_period $= 5.5$ (parameters adapted from [Davies et al. (2020)](https://doi.org/10.1016/S2468-2667(20)30133-X)). We load a contact matrix with age bins 0-18, 18-65, 65 years and older using `{socialmixr}` and assume that one in every 1 million in each age group is infectious at the start of the epidemic.
Using an SEIR model (`model_default_cpp()` in the R package `{epidemics}`) we set $R_0 = 2.7$, preinfectious period $= 4$ and the infectious_period $= 5.5$ (parameters adapted from [Davies et al. (2020)](https://doi.org/10.1016/S2468-2667(20)30133-X)). We load a contact matrix with age bins 0-18, 18-65, 65 years and older using `{socialmixr}` and assume that one in every 1 million in each age group is infectious at the start of the epidemic.

We will assume that school closures will reduce the contacts between school aged children (aged 0-15) by 0.5, and will cause a small reduction (0.01) in the contacts between adults (aged 15 and over).

Expand Down Expand Up @@ -108,34 +108,24 @@ close_schools <- intervention(
```


```{.error}
Error in epidemic_default_cpp(population = uk_population, infection = covid, : could not find function "epidemic_default_cpp"
```


To run the model with an intervention we set ` intervention = list(contacts = close_schools)` as follows:


```r
output_school <- epidemic_default_cpp(
output_school <- model_default_cpp(
population = uk_population,
infection = covid,
intervention = list(contacts = close_schools),
time_end = 300, increment = 1.0
)
```

```{.error}
Error in epidemic_default_cpp(population = uk_population, infection = covid, : could not find function "epidemic_default_cpp"
```


We see that with the intervention (solid line) in place, the infection still spreads through the population, though the epidemic peak is smaller than the baseline with no intervention in place (dashed line).


```{.error}
Error in eval(expr, envir, enclos): object 'output_school' not found
```
<img src="fig/modelling-interventions-rendered-plot_school-1.png" style="display: block; margin: auto;" />

#### Effect of mask wearing on COVID-19 spread

Expand All @@ -160,32 +150,24 @@ To implement this intervention on the parameter $\beta$, we specify `interventio


```r
output_masks <- epidemic_default_cpp(
output_masks <- model_default_cpp(
population = uk_population,
infection = covid,
intervention = list(beta = mask_mandate),
time_end = 300, increment = 1.0
)
```

```{.error}
Error in epidemic_default_cpp(population = uk_population, infection = covid, : could not find function "epidemic_default_cpp"
```




```{.error}
Error in eval(expr, envir, enclos): object 'output_masks' not found
```
<img src="fig/modelling-interventions-rendered-plot_masks-1.png" style="display: block; margin: auto;" />


## Pharmaceutical interventions

Models can be used to investigate the effect of pharmaceutical interventions, such as vaccination. In this case, it is useful to add another disease state to track the number of vaccinated individuals through time. The diagram below shows an SEIRV model where susceptible individuals are vaccinated and then move to the $V$ class.

<!--html_preserve--><div class="grViz html-widget html-fill-item-overflow-hidden html-fill-item" id="htmlwidget-f0beb0255d025fcdcecd" style="width:504px;height:504px;"></div>
<script type="application/json" data-for="htmlwidget-f0beb0255d025fcdcecd">{"x":{"diagram":"digraph {\n\n # graph statement\n #################\n graph [layout = dot,\n rankdir = LR,\n overlap = true,\n fontsize = 10]\n\n # nodes\n #######\n node [shape = square,\n fixedsize = true\n width = 1.3]\n\n S\n E\n I\n R\n V\n\n # edges\n #######\n S -> E [label = \" infection (&beta;)\"]\n S -> V [label = \" vaccination (&nu;)\"]\n E -> I [label = \" onset of \ninfectiousness (&alpha;)\"]\n I -> R [label = \" recovery (&gamma;)\"]\n\n}","config":{"engine":"dot","options":null}},"evals":[],"jsHooks":[]}</script><!--/html_preserve-->
<img src="fig/modelling-interventions-rendered-diagram_SEIRV-1.png" style="display: block; margin: auto;" />

The equations describing this model are as follows:

Expand Down Expand Up @@ -218,24 +200,17 @@ We pass our vaccination object using `vaccination = vaccinate`:


```r
output_vaccinate <- epidemic_default_cpp(
output_vaccinate <- model_default_cpp(
population = uk_population,
infection = covid,
vaccination = vaccinate,
time_end = 300, increment = 1.0
)
```

```{.error}
Error in epidemic_default_cpp(population = uk_population, infection = covid, : could not find function "epidemic_default_cpp"
```

Here we see that the total number of infectious individuals when vaccination is in place is much lower compared to school closures and mask wearing interventions.


```{.error}
Error in eval(expr, envir, enclos): object 'output_vaccinate' not found
```
<img src="fig/modelling-interventions-rendered-plot_vaccinate-1.png" style="display: block; margin: auto;" />


## Summary
Expand Down
50 changes: 14 additions & 36 deletions simulating-transmission.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,7 @@ Mathematical models are useful tools for generating future trajectories of disea

In this tutorial, we will use the R package `{epidemics}` to generate trajectories of influenza spread. By the end of this tutorial, you will be able to generate the trajectory below showing the number of infectious individuals in different age categories through time.


```{.error}
Error in epidemic_default_cpp(population = uk_population, infection = influenza, : could not find function "epidemic_default_cpp"
```

```{.error}
Error in eval(expr, envir, enclos): object 'output' not found
```
<img src="fig/simulating-transmission-rendered-traj-1.png" style="display: block; margin: auto;" />


:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: instructor
Expand All @@ -71,7 +64,7 @@ pak::pak("epiverse-trace/epidemics")
## Model structures
To generate predictions of infectious disease trajectories, we must first select a mathematical model to use.

There is a library of models to choose from in `epidemics`. Models are prefixed with epidemic and suffixed by the infection name. In this tutorial, we will use the default epidemic model, `epidemic_default()` which is described in the next section.
There is a library of models to choose from in `epidemics`. Models are prefixed with `model` and suffixed by the name of infection (e.g. ebola) or a different identifier (e.g. default), and whether the model has a R or C++ code base. In this tutorial, we will use the default epidemic model, `model_default_cpp()` which is described in the next section.


::::::::::::::::::::::::::::::::::::: callout
Expand Down Expand Up @@ -320,23 +313,22 @@ No we are ready to run our model. We will specify `time_end=600` to run the mode


```r
output <- epidemic_default_cpp(
output <- model_default_cpp(
population = uk_population,
infection = influenza,
time_end = 600
)
```

```{.error}
Error in epidemic_default_cpp(population = uk_population, infection = influenza, : could not find function "epidemic_default_cpp"
```

```r
head(output)
```

```{.error}
Error in eval(expr, envir, enclos): object 'output' not found
```{.output}
time demography_group compartment value
1: 0 [0,20) susceptible 14799275
2: 0 [20,40) susceptible 16526302
3: 0 40+ susceptible 28961159
4: 0 [0,20) exposed 0
5: 0 [20,40) exposed 0
6: 0 40+ exposed 0
```
Our model output consists of the number of individuals in each compartment in each age group through time. We can visualise the infectious individuals only (those in the $I$ class) through time.

Expand Down Expand Up @@ -368,9 +360,7 @@ ggplot(output[compartment == "infectious", ]) +
)
```

```{.error}
Error in eval(expr, envir, enclos): object 'output' not found
```
<img src="fig/simulating-transmission-rendered-visualise-1.png" style="display: block; margin: auto;" />


::::::::::::::::::::::::::::::::::::: callout
Expand Down Expand Up @@ -412,7 +402,7 @@ output_samples <- Map(
)

# run an epidemic model using `epidemic()`
output <- epidemic_default_cpp(
output <- model_default_cpp(
population = uk_population,
infection = influenza,
time_end = 600, increment = 1.0
Expand All @@ -427,21 +417,11 @@ output_samples <- Map(
output
}
)
```

```{.error}
Error in epidemic_default_cpp(population = uk_population, infection = influenza, : could not find function "epidemic_default_cpp"
```

```r
# combine to prepare for plotting
output_samples <- bind_rows(output_samples)
```

```{.error}
Error in eval(expr, envir, enclos): object 'output_samples' not found
```


3. Calculate the mean and 95% quantiles of number of infectious individuals across each model simulation and visualise output

Expand All @@ -461,9 +441,7 @@ ggplot(output_samples ,aes(time, value)) +
)
```

```{.error}
Error in eval(expr, envir, enclos): object 'output_samples' not found
```
<img src="fig/simulating-transmission-rendered-plot-1.png" style="display: block; margin: auto;" />


Deciding which parameters to include uncertainty in depends on a few factors: how well informed a parameter value is e.g. consistency of estimates from the literature; how sensitive model outputs are to parameter value changes; and the purpose of the modelling task.
Expand Down

0 comments on commit 9930960

Please sign in to comment.