---
title: Environmental Transmission - Practice
output:
  html_document:
    theme: null
    highlight: null
    fig_retina: null
    fig_caption: true
    mathjax: default 
    keep_md: false
bibliography: references.bib
---


```{r, echo = FALSE}
#this code loads the settings file for the current app so we can automatically 
#list the functions in the further information section
currentrmdfile = knitr::current_input() 
currentappinfo = gsub("_documentation.Rmd" ,"_settings.R",currentrmdfile)
source(currentappinfo)
```


## Overview {#shinytab1}
This app allows you to explore a model which allows for both direct transmission and transmission through an environmental stage. Read about the model in the "Model" tab. Then do the tasks described in the "What to do" tab.


## The Model {#shinytab2}

### Model Overview

This is a simple SIR model with an additional environmental compartment.

This model has the following compartments:  

* **S** - uninfected and susceptible individuals 
* **I** - individuals who are infected and infectious.
* **R** - recovered/removed individuals.
* **E** - pathogen in the environment.


The processes being modeled are:

* Susceptible individuals can become infected by either direct contact with infected hosts at rate _b~d~_ or through contact with a pathogen in the environment at rate _b~e~_.
* Infected hosts recover after some time (specified by the rate _g_). 
* New susceptibles enter (are born) at a rate _b_. From each compartment, hosts "leave" after some time (i.e. they die) at rate _n_. The inverse of this rate is the average lifespan of a host. 
* Infected hosts shed pathogen into the environment at rate _p_.
* Pathogen in the environment decays at rate _c_.


### Model Implementation
The flow diagram and the set of ordinary differential equations (ODE) which are used to implement this model are as follows:


```{r BIdiagram,  fig.cap='Flow diagram for the model with environmental transmission.',  echo=FALSE}
knitr::include_graphics("../media/environmentaltransmissionmodel.png")
```


$$\dot S =b - b_d S I - b_e S E - nS$$ 
$$\dot I = b_d S I + b_e S E - g I -nI$$ 
$$\dot R = g I - nR$$
$$\dot E = p I - cE$$


### A comment on terminology  
Often the letter _E_ is used for the _exposed_ stage, which would then be called a SEIR model. I'm using the letter _E_ here to denote environmental stage of the pathogen. While this could also be abbreviated to SIER (or maybe SIRE), if you see the terminology _SEIR model_ somewhere, the authors usually refer to a model with the additional exposed stage, not an environmental stage. There are no naming rules for either model compartments or parameters, so you will see all kinds of letters used. They should all be explicitly specified by the authors such that there is no ambiguity.


## What to do {#shinytab3}

**The tasks below are described in a way that assumes that everything is in units of MONTHS (rate parameters, therefore, have units of inverse months). If any quantity is not given in those units, you need to convert it first.**


### Task 1: 
* Set the model parameters such that it corresponds to the following setting: 
    * 1000 initially susceptible individuals, _S~0~_, 1 initially infected host, _I~0~_, no pathogen in the environment (_E~0~_ = 0) , simulation duration, _tmax_, approximately 5 years.
    * We'll first look at direct transmission. Set transmission rate of _b~D~ = 0.001_, environmental transmission _b~E~ = 0_.
    * Set environmental pathogen shedding, _p_, and clearance, _c_, to 0. 
    * Assume that the duration of the infectious period is about 2 months long. 
    * Turn off births, _m_, and deaths, _n_, for now.
* Run the simulation. You should get the usual direct transmission dynamics and a single outbreak.
* Record the number and fraction of susceptible/infected/recovered remaining at the end of the outbreak. You should be left with around 202 susceptibles at the end of the simulation. Remember that in a model like this, where the only flow from the susceptible class is outflow through becoming infected, everyone who is not in the susceptible compartment at the end has been infected. Thus the total number of infected during the outbreak is the different between susceptibles at the beginning and at the end.    

### Task 2: 
* Now try various values for the rate of shedding into the environment, _p_, and environmental clearance _c_. Leave everything else unchanged.
* As those parameters move away from 0, what do you expect to see?
* Think about your expectations, run the simulation and compare your expectations with the results.
* Anything surprising happening? Do you understand why you see what you see?


### Task 3: 
* Now set _p = 10_ and _c = 10_ . Turn off direct transmission. Run to make sure you don't get an outbreak.
* Turn on environmental transmission, set it to _b~E~ = 0.001_. Leave everything else unchanged.
* What do you expect to see? Run simulations and compare with the direct transmission results.

### Task 4: 
* Now also turn on direct transmission by setting _b~D~ = b~E~ = 0.001_. Leave everything else unchanged.
* What do you expect to see? Run simulations and see how your expectations hold up.

### Task 5: 
* Now set the initial number of infected to 0 and initial pathogen in the environment to 1. Leave everything else unchanged.
* What do you expect to see? Run simulations and see how your expectations hold up.

### Task 6: 
* Try different combinations of direct and environmental transmission only and having only infected hosts or only pathogen in the environment at the start. 
* What do you expect to see? Run simulations and see how your expectations hold up.

### Task 7: 
* Keep exploring by trying different parameters and transmission settings and see how they influence results.
* You can also turn on births/deaths and see what you get.
* As you continue your exploration, think about potential real infectious diseases that might be approximated by either one of the transmission types, and what settings for other model parameters would be for those ID.


## Further Information {#shinytab4}

* This app (and all others) are structured such that the Shiny part (the graphical interface you see and the server-side function that goes with it) calls an underlying R script (or several) which runs the simulation for the model of interest and returns the results.
* For this app, the underlying function(s) running the simulation are called ``r appsettings$simfunction``. You can call them directly, without going through the shiny app. Use the `help()` command for more information on how to use the functions directly. If you go that route, you need to use the results returned from this function and produce useful output (such as a plot) yourself. 
* You can also download all simulator functions and modify them for your own purposes.  Of course to modify these functions, you'll need to do some coding.
* For examples on using the simulators directly and how to modify them, read the package vignette by typing `vignette('DSAIDE')` into the R console.
* Some more information on environmentally transmitted ID and modeling can be found in [@codeco01].


### References
