---
title: ID Control - Practice
output:
  html_document:
    theme: null
    highlight: null
    css: ../styles/handelshiny.css
    fig_caption: true
    mathjax: default 
    keep_md: false
    includes:
      #in_header: in_header.txt
      before_body: ../styles/before_shiny_body.txt
      after_body: ../styles/after_shiny_body.txt 
bibliography: ../media/references.bib
---

##Overview {#shinytab1}
For this module, we will explore a fairly complex model that allows 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, 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 loose their immunity at rate _w_ and return back 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 simplifcations 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 the mathematical model which are implemented in this app are as follows:

![Flow diagram for this model.](../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 $$ 
    
To keep the diagram from getting too cluttered, births and natural deaths are not drawn.



##What to do {#shinytab3}

###Notes
_All parameters are assumed to be in units of (inverse) 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 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.
* In addition, 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 are quaranting 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. This will likely only be given to symptomatics. 
   * First assume that the drug reduces infectiousness of symptomatics 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 symptomatics, but that asymptomatics and presymptomatics don't transmit.
* Set the model such that only symptomatics transmit, at rate 0.004 and duration of symptomatic period 1 month. Nobody else transmits. Everying 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 symptomatics 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 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 reduction in transmission, e.g. due to the use of bednets.
* 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}

* For this app, the underlying function running the simulation is called `simulate_idcontrol.R`. You can call this function directly, without going through the shiny app. Check the help file for the function for more information. 
* If you call the function directly, you need to process the results returned from this function and produce useful output (such as a plot) yourself. 
* You can also modify this R function for your own purposes. To find out how to do that, type `?DSAIDE` at the R console.
* For some additional reading, see e.g. [@klepac13, @klepac15, @kirsch17, @tognotti13].

### References

