Evaluating forecast accuracy of seasonal methods

As you learned in the first chapter, the window() function specifies the start and end of a time series using the relevant times rather than the index values. Either of those two arguments can be formatted as a vector like c(year, period) which you have also previously used as an argument for ts(). Again, period refers to quarter here.

Here, you will use the Melbourne quarterly visitor numbers (visnights[, "VICMetro"]) to create three different training sets, omitting the last 1, 2 and 3 years, respectively. Inspect the pre-loaded visnights data in your console before beginning the exercise; this will help you determine the correct value to use for the keyword h (which specifies the number of values you want to forecast) in your forecasting methods.

Then for each training set, compute the next year of data, and finally compare the mean absolute percentage error (MAPE) of the forecasts using accuracy(). Why do you think that the MAPE vary so much?

This exercise is part of the course

Forecasting in R

View Course

Exercise instructions

  • Use window() to create three training sets from visnights[,"VICMetro"], omitting the last 1, 2 and 3 years; call these train1, train2, and train3, respectively. Set the end keyword accordingly.
  • Compute one year of forecasts for each training set using the snaive() method. Call these fc1, fc2, and fc3, respectively.
  • Following the structure of the sample code, compare the MAPE of the three sets of forecasts using the accuracy() function as your test set.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Create three training series omitting the last 1, 2, and 3 years
train1 <- window(visnights[, "VICMetro"], end = c(2015, 4))
train2 <- ___
train3 <- ___

# Produce forecasts using snaive()
fc1 <- snaive(___, h = ___)
fc2 <- ___
fc3 <- ___

# Use accuracy() to compare the MAPE of each series
accuracy(fc1, visnights[, "VICMetro"])["Test set", "MAPE"]
___
___