---
title: Multi Pathogen Dynamics - Documentation
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 with 2 pathogens. 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 susceptible hosts, hosts infected with either pathogen 1, pathogen 2 or both, and individuals recovered from infection with pathogen 1, pathogen 2 or both. As usual, infected hosts are assumed to be infectious.

The following compartments are included:  

* **S** - uninfected and susceptible individuals.
* **I~1~** - individuals who are infected with pathogen 1.
* **I~2~** - individuals who are infected with pathogen 2.
* **I~12~** - individuals who are infected with both pathogen 1 and 2.
* **R~1~** - individuals recovered from infection with pathogen 1, still susceptible to pathogen 2.
* **R~2~** - individuals recovered from infection with pathogen 2, still susceptible to pathogen 1.
* **I~1X~** - individuals previously infected with pathogen 2 and now infected with pathogen 1.
* **I~2X~** - individuals previously infected with pathogen 1 and now infected with pathogen 2.
* **R~12~** - individuals recovered from infection with both pathogen 1 and 2.


The included processes/mechanisms are the following:

* Susceptible individuals can become infected with either pathogen 1 or 2.  
* Hosts infected with pathogen 1 or 2 can become infected with the other pathogen.
* Hosts infected with pathogen 1, 2 or both infect susceptibles or hosts infected with the other pathogen at rates _b~1~_/_b~2~_/_b~12~_. For simplicity, we assume that the rates are independent of the status of the host that becomes infected (e.g. an **S** host and a **I~1~** can become infected at the same rates with pathogen 2). It also does not matter if a host has previously recovered from an infection with the other pathogen.
* Hosts infected with both pathogens infect susceptibles with either pathogen 1 or 2 at fractions _a_/_(1-a)_. We do not consider the possibility that both pathogens are transmitted at the same time.
* Infected hosts recover after some time at rates _g~1~_/_g~2~_/_g~12~_. The rate of recovery does not depend on previous infections.
* Recovered individuals are immune to reinfection by the pathogen they have already been infected with (either at the same time or consecutively) but can still be infected with the pathogen they have not yet been infected with. 


### Model Implementation
The flow diagram and the set of differential equations for the mathematical model implemented in this app are as follows:

![Flow diagram for this model.](../media/multipathogenmodel.png)

$$\dot S =  -  (b_{1} (I_1+I_{1X}) + b_{2} (I_2+I_{2X}) + b_{12}I_{12}) S  $$ 
$$\dot I_1 =   (b_{1} (I_1+I_{1X}) + ab_{12} I_{12})S - (g_1  + b_{2} (I_2+I_{2X})  + b_{12}  I_{12}) I_1$$ 
$$\dot I_2 =   (b_{2} (I_2+I_{2X}) +  (1-a) b_{12} I_{12})S - (g_2 + b_{1}(I_1 + I_{1X}) + b_{12} I_{12}) I_2$$ 
$$\dot I_{12} = (b_{2} (I_2+I_{2X})  + b_{12}  I_{12}) I_1 + (b_{1}(I_1 + I_{1X}) + b_{12} I_{12}) I_2  - g_{12} I_{12}$$ 
$$\dot R_1 = g_1 I_1 - (b_2 (I_2 + I_{2X}) + b_{12}  I_{12}) R_1$$
$$\dot R_2 = g_2 I_2 - (b_1 (I_1 + I_{1X}) + b_{12}  I_{12}) R_2$$
$$\dot I_{1X} = (b_1 (I_1 + I_{1X}) + b_{12}  I_{12}) R_2 - g_{1} I_{1X}$$
$$\dot I_{2X} = (b_2 (I_2 + I_{2X}) + b_{12}  I_{12}) R_1 - g_{2} I_{2X}$$
$$\dot R_{12} = g_{1} I_{1X} + g_{2} I_{2X} + g_{12} I_{12} $$




## What to do {#shinytab3}
**The tasks below are described in a way that assumes everything is in units of DAYS (rate parameters, therefore, have units of inverse days). If any quantity is not given in those units, you need to convert it first (e.g. if it says a week, you need to convert it to 7 days).**

### Task 1: 
* First, make sure each pathogen can produce an outbreak by itself.
* Set the initial number of infected with pathogen 1 to 1, all other infected at zero. Susceptibles at 1000.
* Set all transmission rates to 0.001, all recovery rates at 0.5.
* Set fraction of pathogen 1 infections to _a=0.5_.
* Run the simulation for 100 days, check that you only get a single outbreak with pathogen 1.
* Now set initial number of infected with pathogen 1 to 0, with pathogen 2 to 1. Run the simulation and check that you get exactly the same size outbreak with pathogen 2.

### Task 2: 
* Leave everything as before but now start with 1 infected for both pathogen 1 and 2. You should see outbreaks for both pathogens with the same dynamics (in fact, you won't see the curves for _I~1~_, _R~1~_, etc. since they are covered by the curves for _I~2~_, _R~2~_.)

### Task 3: 
* Now start with _I~10~=1_ and _I~20~=10_. What do you expect to see? What do you find?

### Task 4: 
* Go back to _I~10~ = I~20~ = 1_, instead set _b~2~ = 0.002_. What do you expect to see? What do you find?
* What do you conclude has the stronger impact, higher initial number of infected for pathogen 2 or higher transmissibility?

### Task 5: 
* To confirm that things are completely "symmetric", redo the 2 previous tasks but now instead of changing pathogen 2 initial infected or transmission rate, do it for pathogen 1.

### Task 6:
* Set everything back as in task #2, i.e. the 2 pathogens have the same starting numbers and transmission rates.
* Now play around with the fraction of pathogen 1 infections, _a_. What do you expect? What do you find?

### Task 7:
* Keep exploring. Investigate how some of the other parameters influence the outbreak dynamics for the 2 pathogens.
* Always follow the same pattern: Think about what you results you expect to get from a certain scenario/parameter setting and why. Then check with the simulation. If things don't agree, figure out why not. 



## 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.


### References

