---
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}

n=1000

gamma = 0.2
days1 = 100
days2= 1
R01 =  rep(seq(1,5,length=10),each=10)
R02 = 0.3
R012 = rep(seq(0,1,length=10),times=10)
R11 = 2.5
R12 = 1
R112 = 1
d<-data.frame(gamma=gamma,days1,days2,R01=R01,R02=R02,R012=R012, R11=R11,R12=R12,R112=R112)
d %>% rowwise %>%  mutate(R1=final_R(R01=R01,R02=R02,R012=R012)$R1, R2=final_R(R01=R01,R02=R02,R012=R012)$R2) -> d
```


```{r}

```


```{r}
ggplot(d, aes(R012,R01)) +geom_tile(aes(fill = R2))
```


```{r}
ggplot(d, aes(x=R01,y=R2)) +  geom_point()
```



```{r}
gamma = 0.2
days1 = 100
days2= 1
R01 =  runif(1000,0.3,8)
R02 =  0.3
R012 = runif(1000,0.3,1)
R11 = 2.5
R12 = 1
R112 = 1
d<-data.frame(gamma=gamma,days1,days2,R01=R01,R02=R02,R012=R012, R11=R11,R12=R12,R112=R112)
d %>% rowwise %>%  mutate(R1=final_R(R01=R01,R02=R02,R012=R012)$R1, R2=final_R(R01=R01,R02=R02,R012=R012)$R2) -> d
```

```{r}
d %>% filter(R2<0.4) -> dd

ggplot(dd,aes(y=R01,x=R012)) +geom_point()
```


