---
title: Host Heterogeneity - 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 simple SIR model with 2 types of hosts. 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 tracks susceptibles, infected and recovered of 2 different types. Think of those types as e.g. males/females, children/adults, etc. 

The following compartments are included, twice for each type (i=1,2):  

* **S~i~** - uninfected and susceptible individuals 
* **I~i~** - individuals who are infected and infectious.
* **R~i~** - recovered/removed individuals. Those individuals have recovered and are immune. 


The included processes/mechanisms are the following:

* Susceptible individuals of type 1 or 2 can become infected by infected hosts of type 1 or 2. The rates at which infections from type 1/2 to type 1/2 occur are given by the parameters _b~11~_, _b~12~_, _b~21~_ and _b~22~_. 
* Infected hosts of type 1/2 recover after some time at rates _g~1~_/_g~2~_. 
* Recovered individuals are initially immune to reinfection. They can lose their immunity at rates _w~1~_/_w~2~_ and return back to the susceptible state. 
* New susceptible hosts and vectors enter the system at rates _e~1~_ and _e~2~_. Natural death occurs at rates _n~1~_ and _n~2~_. 



###Model Implementation
The flow diagram and the mathematical model which are implemented in this app are as follows:

![Flow diagram for this model. Natural births and deaths are not drawn.](../media/heterogeneitymodel.png)

$$\dot S_1 = e_1 - S_1 (b_{11} I_1 + b_{12} I_2) + w_1 R_1 - n_1 S_1 $$ 
$$\dot I_1 =  S_1 (b_{11} I_1 + b_{12} I_2) - g_1 I_1 - n_1 I_1 $$ 
$$\dot R_1 = g_1 I_1 - w_1 R_1 - n_1 R_1$$
$$\dot S_2 = e_2 - S_2 (b_{22} I_2 + b_{21} I_1) + w_2 R_2 - n_2 S_2 $$ 
$$\dot I_2 =  S_2 (b_{22} I_2 + b_{21} I_1) - g_2 I_2 - n_2 I_2 $$ 
$$\dot R_2 = g_2 I_2 - w_2 R_2 - n_2 R_2$$




##What to do {#shinytab3}


###Task 1: 
* Set the model parameters such that it corresponds to the following setting: 
    * 1000 susceptible hosts and 1 infected host of type 1.
    * 200 susceptible hosts and 1 infected host of type 2.
    * Simulation duration approximately 5 years.
    * Assume that transmission from host 1 to 1 is 0.002, from host 2 to 2 is 0.01. No transmission from one host type to the other.
    * Assume that the duration of the infectious period is 1 month long for both types. 
    * Assume nobody dies due to disease, and immunity does not wane.
    * No waning immunity or natural births/deaths.
    
* With parameters set to correspond to the scenario just described, run the simulation and ensure you get outbreaks in both populations with 20% susceptibles left at the end.

###Task 2: 
* Set the transmission rate from host 1 to host 1 to 0.001. Rest as before. Run the simulation.
* Now set the transmission rate from host 2 to host 1 to 0.001. You should see an outbreak in both populations. This is an example of a core group driving the dynamics. Contemplate what the core group does.

###Task 3: 
* Keep all settings as before, but set initial number of infected type 1 hosts to 0. 
* Contemplate what you expect to see, run simulation, see if your expectations are confirmed.
* Now set initial number of infected type 1 hosts back to 1, infected type 2 hosts to 0. 
* Contemplate what you expect to see, run simulation, see if your expectations are confirmed.

###Task 4: 
* Set the transmission rate from host 1 to host 1 to 0. Same for the transmission rate between type 2 hosts. 
* Set the transmission rate  from host 2 to host 1 to 0.01, from host 1 to host 2 to 0.002. Those are the same values used on task 1 for transmission among the same hosts. 
* Set number of initial infected of type 1 and 2 both to 1.
* Contemplate what you expect to see, run simulation, see if your expectations are confirmed.
* Now set the transmission rate from host 1 to host 2 to 0.01, from host 2 to host 1 to 0.002. Again, think about your expectations, run simulation and check.

###Task 5: 
* Repeat the previous task, with only infected of type 1 initially present.
* Contemplate what you expect to see, run simulation, see if your expectations are confirmed.

###Task 6: 
* Repeat the previous task, with only infected of type 2 initially present.
* Contemplate what you expect to see, run simulation, see if your expectations are confirmed.

###Task 7: 
* Set everything as in task 1, but with waning immunity for both types at a rate 0.2.
* Run simulation, confirm that both populations reach a steady endemic state.
* Set transmission from type 2 to type 1 to 0.005, run simulation and see what changes.
* Set transmission from type 1 to type 2 to 0.005, other cross-transmission back to 0. Run simulation and see what changes.

###Task 8: 
* With the settings you just had, turn off waning immunity for type 1, run simulation and see what you get.
* Turn waning immunity for type 1 back on and turn off for type 2, run simulation and see what you get.

###Task 9: 
* Keep exploring. Think of a real ID where accounting for 2 types of hosts is important, see if you can use the simulation to approximate and explore that ID.

  


##Further Information {#shinytab4}

* For this app, the underlying function running the simulation is called `simulate_heterogeneity.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 more information dealing with host heterogeneity, see e.g. [@beldomenico10, @yorke78, @lloyd-smith05].

### References
