---
title: "Sensitivity analysis"
author: "Duncan Golicher"
date: "13/10/2020"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```


```{r}
library(gbd)
library(deSolve)
library(tidyverse)
theme_set(theme_bw())
```


## Examples

```{r}
d1<-run_sim(gamma = 0.2,days1 = 100,days2= 100,R01 =  3,R02 = 0.3,R012 = 0.1,R11 = 2.5,R12 = 1,R112 = 1)
d1$R01=3
d2<-run_sim(gamma = 0.2,days1 = 100,days2= 100,R01 =  1.6,R02 = 0.3,R012 = 0.1,R11 = 2.5,R12 = 1,R112 = 1)
d2$R01=1.6
d3<-run_sim(gamma = 0.2,days1 = 100,days2= 100,R01 =  1.4,R02 = 0.3,R012 = 0.1,R11 = 2.5,R12 = 1,R112 = 1)
d3$R01=1.4
d4<-run_sim(gamma = 0.2,days1 = 100,days2= 100,R01 =  1.1,R02 = 0.3,R012 = 0.1,R11 = 2.5,R12 = 1,R112 = 1)
d4$R01=1.1
d<-rbind(d1,d2,d3,d4)
```

```{r}
d %>% pivot_longer(c(2:7)) %>% separate(name,into=c("Class", "group"), sep=1,remove=FALSE) %>% filter(Class !="S") -> dd
ggplot(dd,aes(x=time,y=value,col=name)) + geom_line() +facet_wrap(~R01) + geom_vline(aes(xintercept=100),col="grey")
```



```{r}
d1<-run_sim(gamma = 0.2,days1 = 100,days2= 100,R01 =  3,R02 = 0.3,R012 = 0.1,R11 = 2.5,R12 = 1,R112 = 1)
d1$R012=0.1
d2<-run_sim(gamma = 0.2,days1 = 100,days2= 100,R01 =  3,R02 = 0.3,R012 = 0.4,R11 = 2.5,R12 = 1,R112 = 1)
d2$R012=0.4
d3<-run_sim(gamma = 0.2,days1 = 100,days2= 100,R01 =  3,R02 = 0.3,R012 = 0.6,R11 = 2.5,R12 = 1,R112 = 1)
d3$R012=0.6
d4<-run_sim(gamma = 0.2,days1 = 100,days2= 100,R01 =  3,R02 = 0.3,R012 = 1,R11 = 2.5,R12 = 1,R112 = 1)
d4$R012=1
d<-rbind(d1,d2,d3,d4)
```

```{r}
d %>% pivot_longer(c(2:7)) %>% separate(name,into=c("Class", "group"), sep=1,remove=FALSE) %>% filter(Class !="S") -> dd
ggplot(dd,aes(x=time,y=value,col=name)) + geom_line() +facet_wrap(~R012) + geom_vline(aes(xintercept=100),col="grey")
```


## Circuit break!!

## Examples

```{r}
d1<-run_sim(gamma = 0.2,days1 = 100,days2= 100,R01 =  3,R02 = 0.3,R012 = 0.1,R11 = 2.5,R12 = 1,R112 = 1)
d1$R01=3
d2<-run_sim(gamma = 0.2,days1 = 100,days2= 100,R01 =  1.6,R02 = 0.3,R012 = 0.1,R11 = 2.5,R12 = 1,R112 = 1)
d2$R01=1.6
d3<-run_sim(gamma = 0.2,days1 = 100,days2= 100,R01 =  1.4,R02 = 0.3,R012 = 0.1,R11 = 2.5,R12 = 1,R112 = 1)
d3$R01=1.4
d4<-run_sim(gamma = 0.2,days1 = 100,days2= 100,R01 =  1.1,R02 = 0.3,R012 = 0.1,R11 = 2.5,R12 = 1,R112 = 1)
d4$R01=1.1
d<-rbind(d1,d2,d3,d4)
```

```{r}
d %>% pivot_longer(c(2:7)) %>% separate(name,into=c("Class", "group"), sep=1,remove=FALSE) %>% filter(Class !="S") -> dd
ggplot(dd,aes(x=time,y=value,col=name)) + geom_line() +facet_wrap(~R01) + geom_vline(aes(xintercept=100),col="grey")
```



```{r}
d1<-run_circuit_break(gamma = 0.2,days1 = 10,days2= 100,R01 =  3,R02 = 0.3,R012 = 0.1,R11 = 2.5,R12 = 1,R112 = 1)
d1$R012=0.1
d2<-run_circuit_break(gamma = 0.2,days1 = 10,days2= 100,R01 =  3,R02 = 0.3,R012 = 0.4,R11 = 2.5,R12 = 1,R112 = 1)
d2$R012=0.4
d3<-run_circuit_break(gamma = 0.2,days1 = 10,days2= 100,R01 =  3,R02 = 0.3,R012 = 0.6,R11 = 2.5,R12 = 1,R112 = 1)
d3$R012=0.6
d4<-run_circuit_break(gamma = 0.2,days1 = 10,days2= 100,R01 =  3,R02 = 0.3,R012 = 1,R11 = 2.5,R12 = 1,R112 = 1)
d4$R012=1
d<-rbind(d1,d2,d3,d4)
```

```{r}
d %>% pivot_longer(c(2:7)) %>% separate(name,into=c("Class", "group"), sep=1,remove=FALSE) %>% filter(Class !="S") -> dd
ggplot(dd,aes(x=time,y=value,col=name)) + geom_line() +facet_wrap(~R012) + geom_vline(aes(xintercept=100),col="grey")
```


```{r}
d1<-run_sim(gamma = 0.2,days1 = 10,days2= 100,R01 =  3,R02 = 0.3,R012 = 0.1,R11 = 2.5,R12 = 1,R112 = 1)
d1$R012=0.1
d2<-run_sim(gamma = 0.2,days1 = 10,days2= 100,R01 =  3,R02 = 0.3,R012 = 0.4,R11 = 2.5,R12 = 1,R112 = 1)
d2$R012=0.4
d3<-run_sim(gamma = 0.2,days1 = 10,days2= 100,R01 =  3,R02 = 0.3,R012 = 0.6,R11 = 2.5,R12 = 1,R112 = 1)
d3$R012=0.6
d4<-run_sim(gamma = 0.2,days1 = 10,days2= 100,R01 =  3,R02 = 0.3,R012 = 1,R11 = 2.5,R12 = 1,R112 = 1)
d4$R012=1
d<-rbind(d1,d2,d3,d4)
```

```{r}
d %>% pivot_longer(c(2:7)) %>% separate(name,into=c("Class", "group"), sep=1,remove=FALSE) %>% filter(Class !="S") -> dd
ggplot(dd,aes(x=time,y=value,col=name)) + geom_line() +facet_wrap(~R012) + geom_vline(aes(xintercept=100),col="grey")
```









