Get startedGet started for free

ETS vs seasonal naive

Here, you will compare ETS forecasts against seasonal naive forecasting for 20 years of cement, which contains quarterly cement production using time series cross-validation for 4 steps ahead. Because this takes a while to run, a shortened version of the cement series will be available in your workspace.

The second argument for tsCV() must return a forecast object, so you need a function to fit a model and return forecasts. Recall:

> args(tsCV)
function (y, forecastfunction, h = 1, ...)

In this exercise you will use an existing forecasting function as well as one that has been created for you. Remember, sometimes simple methods work better than more sophisticated methods!

This exercise is part of the course

Forecasting in R

View Course

Exercise instructions

  • A function to return ETS forecasts, fets(), has been written for you.
  • Apply tsCV() for both ETS and seasonal naive methods to the cement data for a forecast horizon of 4. Use the newly created fets and the existing snaive functions as your forecast function argument for e1 and e2, respectively.
  • Compute the MSE of the resulting 4-step errors and remove missing values. The expressions for calculating MSE have been provided for you, but the second optional arguments have not (you've used them before).
  • Save the best MSE as bestmse. You can simply copy the entire line of code that generates the best MSE from the previous instruction.

Hands-on interactive exercise

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

# Function to return ETS forecasts
fets <- function(y, h) {
  forecast(ets(y), h = h)
}

# Apply tsCV() for both methods
e1 <- tsCV(___, ___, h = ___)
e2 <- tsCV(___, ___, h = ___)

# Compute MSE of resulting errors (watch out for missing values)
mean(e1^2, ___)
mean(e2^2, ___)

# Copy the best forecast MSE
bestmse <- ___
Edit and Run Code