---
title: "Swiss ILI surveillance counts"
author: "Sebastian Meyer"
date: "`r Sys.Date()`"
output:
    rmarkdown::html_vignette:
        fig_width: 6
        fig_height: 4
vignette: >
  %\VignetteIndexEntry{Swiss ILI surveillance counts}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteDepends{ggplot2}
---

```{r setup_knitr, include = FALSE}
knitr::opts_chunk$set(message = FALSE, warning = FALSE, error = FALSE,
                      fig.align = "center", dev.args = list(pointsize = 10))
```

```{r setup}
library("HIDDA.forecasting")
library("ggplot2")
source("setup.R", local = TRUE)  # define TRAIN, TEST and OWA periods
```

We will compute one-week-ahead forecasts for the last `r length(OWA)` weeks
(starting from the vertical dashed line in the plot below), as well as
`r length(TEST[[1]])`-week-ahead forecasts for the last `r length(TEST)` seasons
(highlighted in the plot below).

```{r CHILI}
autoplot(CHILI) +
    labs(x = "Time (week)", y = "ILI counts in Switzerland") +
    geom_vline(xintercept = index(CHILI)[min(unlist(TEST))], lty = 2) +
    geom_rect(aes(xmin=xmin, xmax=xmax, ymin=0, ymax=Inf),
              data=data.frame(xmin=index(CHILI)[sapply(TEST, min)],
                              xmax=index(CHILI)[sapply(TEST, max)]),
              inherit.aes=FALSE, alpha=0.3) +
    scale_y_sqrt(expand = c(0,0), limits = c(0,NA))
```

```{r CHILIdat}
CHILIdat <- within(fortify(CHILI), {
    Year = as.factor(strftime(Index, "%Y"))
    DayInYear = as.integer(strftime(Index, "%j"))
    WeekInYear = as.integer(strftime(Index, "%V"))
})
```

```{r seasonality}
## ggplot(CHILIdat, aes(x = DayInYear, y = CHILI, col = Year)) + geom_line()
ggplot(CHILIdat, aes(x = WeekInYear, y = CHILI, col = Year)) + geom_line() +
    scale_y_sqrt(expand = c(0,0), limits = c(0,NA)) +
    guides(col = guide_legend(ncol = 2)) #+ theme(legend.position = "bottom")
```
