0

I am looking for a simple example (or link to one) that uses either base Holt-Winters or one from the forecast package in R to plot the actuals over the same range as the prediction.

I have seen many examples that show the actuals/fitted together, or the actuals 'followed by' the prediction, but I cant find a code example with the actuals/predicted running together.

My reason for this is to create a prediction using a subset of the actuals (train) and then drop the full dataset in so I can show how well the prediction really did. Hope that makes sense, and thanks in advance for any help!

JD1
  • 27
  • 5

1 Answers1

0

Found a pretty simple solution to this using the dygraph package. This may be a simple thing, but leaving my question/answer out here incase other newbies come across and trying to do the same thing:

I took the code from this link (2nd graph): https://rstudio.github.io/dygraphs/gallery-upper-lower-bars.html

And modified to this:

library(dygraphs)
library(magrittr)

#hw <- HoltWinters(ldeaths)
hw <- HoltWinters(window(ldeaths, 1974, c(1976,12)))        #subset timeseries to first 3 years in ldeath (train data)
p <- predict(hw, n.ahead = 36, prediction.interval = TRUE)  #predict for the last 3 years in ldeath (test data)
all <- cbind(ldeaths, p) #we add full ldeaths into graph to see test data (1977,78,79) against the prediction

dygraph(all, "Deaths from Lung Disease (UK)") %>%
  dySeries("ldeaths", label = "Actual") %>%
  dySeries(c("p.lwr", "p.fit", "p.upr"), label = "Predicted")
JD1
  • 27
  • 5