---
title: Host Heterogeneity - Practice
output:
  html_document:
    theme: null
    highlight: null
    css: ../styles/dsaide.css
    fig_caption: true
    mathjax: default 
    keep_md: false
    includes:
      #in_header: in_header.txt
      before_body: ../styles/dsaide_before_body.txt
      after_body: ../styles/dsaide_after_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 to the susceptible state. 
 


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

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

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




##What to do {#shinytab3}


**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).**


###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 host 1 is _b~11~ = 0.002_, from host 2 to host 2 is _b~22~ = 0.01_. No transmission from one host type to the other _b~12~ = 0_ and _b~21~ = 0_.
 * Assume that the duration of the infectious period is 1 month long for both types ( _g~1~_ and _g~2~_ ). 
 * No waning immunity.
 * Run the simulation and ensure you get outbreaks in both populations with 20% susceptibles left at the end.

###Task 2: 
* Set _b~11~ = 0.001_. Rest as before. 
* Run the simulation. You should get the same outbreak as before among type 2 hosts, no real outbreak among type 1 hosts.
* If you have worked through the reproductive number app already, contemplate what R was for both types/populations in task 1, what it is now in task 2, and how that influences what you see in the simulation. 

###Task 3: 
* Now set the transmission rate from host 2 to host 1 _b~21~ = 0.001_. Everything as before.
* Run the simulation. 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 4: 
* Keep all settings as before, but set initial number of infected type 1 hosts to 0.
* Contemplate what you expect to see, run the simulation, see if your expectations are confirmed.

###Task 5: 
* Now set the initial number of infected type 1 hosts back to 1, and infected type 2 hosts to 0. 
* Contemplate what you expect to see, run the simulation, see if your expectations are confirmed.

###Task 6: 
* Set _I1~0~ = 1_ and _I2~0~ = 1_.
* Set the transmission rates from host 1 to host 1 and host 2 to host 2 to 0. 
* Set the transmission rate from host 2 to host 1 to _b~21~_ = 0.01, from host 1 to host 2 to _b~12~_ = 0.002. Those are the same values used in task 1 for transmission among the same hosts.
* Contemplate what you expect to see, run the simulation, see if your expectations are confirmed.

Transmission only between hosts of different type could for instance represent a sexually transmitted disease in a heterosexual population, with the 2 types of hosts being females and males.

###Task 7: 
* Now set the transmission rate _b~12~ = 0.01_, and _b~21~ = 0.002_. Everything else as before.
* Again, think about your expectations, run simulation and check.

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

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

###Task 10: 
* Set everything back as in task 1, but with waning immunity with an average duration of immunity of 5 months for each population (i.e. rates _w~1~_ and _w~2~_ need to be the inverse of 5 months.).
* Run simulation, confirm that both populations reach a steady endemic state.

###Task 11: 
* Set transmission rate _b~21~ = 0.005_, everything else as before.
* Run the simulation and see what changes.

###Task 12: 
* Set transmission rate _b~12~ = 0.005_, and _b~21~ = 0_, everything else as before. 
* Run the simulation and see what changes.

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

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

###Task 15: 
* 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
