---
title: ID Control 2 - 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}
For this module, we will explore a fairly complex model that allows the study of different types of interventions. 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 model is fairly big and has many parts that can be turned on or off depending on parameter settings. The model allows for 3 types of transmission: direct, through an environmental stage, and through a vector stage. The (human) host is modeled in some detail, the environment and vectors are modeled with 1 and 2 compartments. 
The following compartments are included:  

* **S** - uninfected and susceptible individuals 
* **P** - individuals who are infected and do not yet show symptoms. Those individuals can potentially be infectious
* **A** - individuals who are infected and do not show symptoms. Those individuals can potentially be infectious
* **I** - individuals who are infected and show symptoms. Those individuals are likely infectious, but the model allows to adjust this, including no infectiousness.
* **R** - recovered/removed individuals. Those individuals have recovered and are immune. They can loose their immunity in this model.
* **D** - individuals who have died due to the disease.
* **E** - pathogen in the environment
* **S~V~** - susceptible vectors
* **I~V~** - infected/infectious vectors


The included processes/mechanisms are the following:

* Susceptible individuals (S) can become infected by pre-symptomatic (P), asymptomatic (A) or symptomatic (I) hosts. The rates at which infections from the different types of infected individuals (P, A and I) occur are governed by 3 parameters, _b~P~_, _b~A~_, and _b~I~_. 
* Susceptible individuals (S) can also become infected by contact with the environment or infected vectors, at rates _b~E~_ and _b~v~_. 
* Susceptible vectors (S~v~) can become infected by contact with symptomatic hosts at rate _b~h~_. 
* All infected hosts first enter the presymptomatic stage. They remain there for some time (determined by rate _g~P~_, the inverse of which is the average time spent in the presymptomatic stage). 
A fraction _f_ of presymptomatic hosts move into the asymptomatic category, and the rest become symptomatic infected hosts.
* Asymptomatic infected hosts recover after some time (specified by the rate _g~A~_). Similarly, the rate _g~I~_ determines the duration the symptomatic hosts stay in the symptomatic state. For symptomatic hosts, two outcomes are possible. Either recovery or death. The parameter _d_ determines the fraction of hosts that die.
* Recovered individuals are initially immune to reinfection. They can lose their immunity at rate _w_ and return to the susceptible compartment. 
* Symptomatic and asymptomatic hosts shed pathogen into the environment at rates p~A~ and p~I~. The pathogen in the environment decays at rate _c_.
* New susceptible hosts and vectors enter the system (are born) at rates _e~h~_ and _e~v~_. Natural death for hosts and vectors occurs at rates _n~h~_ and _n~v~_. (In the code, those rates are called birth~i~ and death~i~).

Note that we only track people that die due to the disease in our _D_ compartment. All hosts dying due to other causes just "exit the system" and we don't further keep track of them (though we could add another compartment to "collect" and track all individuals who died from non-disease-related causes.)

Also, note that we made several simplifications to keep the model from getting too complex. For instance, presymptomatic individuals do not shed into the environment, and only symptomatic hosts are assumed to be able to infect vectors. Further details relaxing these assumptions could, of course, be included, at the expense of a larger and more complex model.


### Model Implementation
The flow diagram and equations describe the model implemented in this app:




```{r BIdiagram,  fig.cap='Flow diagram for this model. ',  echo=FALSE}
knitr::include_graphics("../media/idcontrolmodel.png")
```


$$\dot S = e_h - S (b_P P + b_A A + b_I I + b_E E + b_v I_v) + wR - n_h S $$ 
$$\dot P = S (b_P P + b_A A + b_I I + b_E E + b_v I_v) - g_P P - n_h P$$ 
$$\dot A = f g_P P - g_A A - n_h A$$ 
$$\dot I = (1-f) g_P P - g_I I - n_h I $$ 
$$\dot R = g_A A + (1-d) g_I I - wR - n_h R$$
$$\dot D = d g_I I $$
$$\dot E = p_I I + p_A A - c  E $$
$$\dot S_v = e_v  - b_h  I  S_v - n_v  S_v $$ 
$$\dot I_v = b_h I S_v - n_v  I_v $$ 
    
Births and natural deaths are not drawn to keep the diagram from getting too cluttered.



## What to do {#shinytab3}

### Notes

**The tasks below are described in a way that assumes 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 (e.g. if it says a year, you need to convert it to 12 months).**

_Some of the simulations might take a few seconds to run. Be patient._


### Task 1: 
* Set the model parameters such that it corresponds to the following setting: 
    * 1000 susceptible hosts and vectors, 1 initially symptomatic host, no infected vectors or pathogen in the environment.
    * Simulation duration approximately 5 years.
    * Assume that only symptomatic individuals transmit, at a rate of 0.002. All other transmission rates should be 0.
    * Assume that the duration of the symptomatic period is 1 month long, the duration of the presymptomatic period is half a month long. 
    * Assume that there are no asymptomatic infections. You can, therefore, set the rate of recovery of asymptomatics to anything, it doesn't matter because nobody will be asymptomatic.
    * Assume that no environmental shedding and decay occurs.
    * Assume nobody dies due to disease, and immunity does not wane.
    * Assume that there are no births and non-disease deaths occurring.
    
* With parameters set to correspond to the scenario just described, run the simulation and ensure you get a single outbreak with 20% susceptibles left at the end.

### Task 2: 
* Let's now assume that 50% of infected hosts are asymptomatic and that the duration of the asymptomatic stage is the same as the symptomatic stage.
* Also, assume that asymptomatic infected are half as infectious as symptomatic infected, and that pre-symptomatic are as infectious as symptomatic.
* Run the simulation, you should get an outbreak with around 11% susceptibles left.
* Assume that we quarantine hosts, and that quarantining reduces infectiousness by half. 
  * First, we envision a scenario where we can only detect and quarantine individuals that show symptoms. Implement such a scenario, run the simulation and record the number of susceptibles left at the end.
  * Next, we envision a scenario where we can quarantine everyone who has become infected, independent of symptom status. Implement such a scenario, again run the simulation and record the number of susceptibles left at the end.
  
### Task 3: 
* Change settings back as they were before you implemented quarantine. 
* Now assume that we can administer a drug. It will likely only be given to symptomatic individuals. 
   * First assume that the drug reduces the infectiousness of symptomatic individuals by half. Run the simulation, record the number of susceptibles at the end of the outbreak. 
   * Now assume that the drug _also_ reduces the duration of the symptomatic period from a month (30 days) to 20 days. Run the simulation, record the number of susceptibles at the end of the outbreak. 

### Task 4: 
* Of course, intervention strategies are best if they reach all that transmit. Let's assume now that we still have a drug that targets symptomatic individuals, but that asymptomatic and presymptomatic individuals don't transmit.
* Set the model such that only symptomatic individuals transmit, at rate 0.004 and duration of the symptomatic period to 1 month. Nobody else transmits. Everything else should be as in task 2. You should get an outbreak of the same size as in task 1.
* Now assume that the drug reduces the duration of the symptomatic period from a month (30 days) to 20 days. Run the simulation, record the number of susceptibles at the end of the outbreak. 
* Now assume that the drug also cuts infectiousness by half. Run the simulation, record the number of susceptibles at the end of the outbreak. 


### Task 5: 
* Set everything as in task 1. Then turn on environmental shedding by symptomatic individuals and decay both at rates of 1 per month. Run an outbreak, record the number of susceptibles at the end.

### Task 6: 
* Set rate of transmission from the environment to susceptible hosts to 0.002. Run the simulation.
* Turn off the rate of direct transmission between hosts. Make sure you still get an outbreak. 
* Let's assume different interventions that affect the environmental transmission.
  * First, we consider an intervention that leads to a 50% increased pathogen clearance from the environment. Implement that and run the simulation.
  * Instead of faster clearance, assume a 50% reduced rate of infection from the environment. Implement that and run the simulation.

### Task 7: 
* We'll now switch to vector-borne transmission. Set everything as in task 1, introduce 1 infected vector.   
* Assume that transmission between hosts does not occur. Set transmission from host to vector and vector to host to 0.001. 
* Run the simulation. Observe the dynamics of the vectors.
* Now allow for vector births and deaths. Assume that vectors (say mosquitoes) live for half a month. Set birth rate such that vector population balances at 1000. Run the simulation.
* Double host-vector and vector-host transmission rates. Now consider some vector control measures.
* Assume we sprayed against mosquitoes and it reduced the population size by 90%. Set the initial vector population to that value, run the outbreak, observe.

### Task 8: 
* Instead of killing vector populations, we now consider a reduction in transmission, e.g. due to the use of bed nets.
* Set everything as in task 7 (minus the intervention). Assume that an intervention reduces transmission _to_ vectors by half. Run the simulation, observe.
* Now assume that an intervention reduces transmission _from_ vectors by half. Run the simulation, observe.
* Finally, assume that the intervention reduces transmission both to and from vectors by half. Run the simulation, observe.
  
### Task 9: 
* Keep exploring. The model has many more parameters that you can change, e.g. allowing births and deaths and waning immunity for hosts, or ID that transmit through multiple routes at the same time (e.g. Zika virus). Investigate how different control strategies work under different scenarios.
  

## 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.
* For some additional reading, see e.g. [@klepac13, @klepac15, @kirsch17, @tognotti13].

### References

