---
title: "Comparing outcomes across vaccination strategies"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Comparing outcomes across vaccination strategies}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

This example shows how to compare across multiple vaccination scenarios with uncertainty in $R_0$, for an H1H1-like infection in the U.K.
The example is aimed at showing how _daedalus_ and _daedalus.compare_ can be used for vaccination impact modelling.

```{r setup}
library(daedalus) # needed for custom vaccination objects
library(daedalus.compare)

country <- "GB"

# make list of infection objects
set.seed(1)
infection_list <- make_infection_samples(
  "influenza_2009",
  param_distributions = list(
    r0 = distributional::dist_beta(2, 5)
  ),
  param_ranges = list(
    r0 = c(1.0, 2.0)
  ),
  samples = 10
)

# create three vaccination scenarios including a no-vaccination scenario
# this example uses pre-canned scenarios from daedalus
no_vaccination <- NULL
late_vaccination <- daedalus_vaccination("low", country)
early_vaccination <- daedalus_vaccination("high", country)
```

Run `run_scenarios()`, passing the vaccination scenarios to the argument `vaccination_strategy` as a list.

```{r run_scenarios}
# run over a period of 400 days as late vaccination
# begins on day 300
output <- run_scenarios(
  country, infection_list,
  vaccination_strategy = list(
    none = no_vaccination,
    late_vaccination = late_vaccination,
    early_vaccination = early_vaccination
  ),
  time_end = 400
)

# view output which is a data.table with a nested list column
output

# get epi-curve data
disease_tags <- sprintf("sample_%i", seq_along(infection_list))
epi_curves <- get_epicurve_data(output, disease_tags)
```

```{r}
# plot epi-curve data showing daily hospitalisations
library(dplyr)
library(ggplot2)

epi_curves %>%
  filter(measure == "daily_hospitalisations") %>%
  ggplot(aes(time, value)) +
  geom_line(
    aes(col = vaccination, group = interaction(tag, vaccination))
  ) +
  labs(
    x = "Time", y = "Daily hospitalisations",
    col = "Mitigation strategy"
  )
```
