knitr::opts_chunk$set(message = FALSE, warning = FALSE, error = FALSE, fig.align = "center", dev.args = list(pointsize = 10))
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).
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))
CHILIdat <- within(fortify(CHILI), { Year = as.factor(strftime(Index, "%Y")) DayInYear = as.integer(strftime(Index, "%j")) WeekInYear = as.integer(strftime(Index, "%V")) })
## 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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.