Get startedGet started for free

Checking time series residuals

When applying a forecasting method, it is important to always check that the residuals are well-behaved (i.e., no outliers or patterns) and resemble white noise. The prediction intervals are computed assuming that the residuals are also normally distributed. You can use the checkresiduals() function to verify these characteristics; it will give the results of a Ljung-Box test.

You haven't used the pipe function (%>%) so far, but this is a good opportunity to introduce it. When there are many nested functions, pipe functions make the code much easier to read. To be consistent, always follow a function with parentheses to differentiate it from other objects, even if it has no arguments. An example is below:

> function(foo)       # These two
> foo %>% function()  # are the same!

> foo %>% function    # Inconsistent

In this exercise, you will test the above functions on the forecasts equivalent to what you produced in the previous exercise (fcgoog obtained after applying naive() to goog, and fcbeer obtained after applying snaive() to ausbeer).

This exercise is part of the course

Forecasting in R

View Course

Exercise instructions

  • Using the above pipe function, run checkresiduals() on a forecast equivalent to fcgoog.
  • Based on this Ljung-Box test results, do the residuals resemble white noise? Assign googwn to either TRUE or FALSE.
  • Using a similar pipe function, run checkresiduals() on a forecast equivalent to fcbeer.
  • Based on this Ljung-Box test results, do the residuals resemble white noise? Assign beerwn to either TRUE or FALSE.

Hands-on interactive exercise

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

# Check the residuals from the naive forecasts applied to the goog series
goog %>% naive() %>% ___

# Do they look like white noise (TRUE or FALSE)
googwn <- ___

# Check the residuals from the seasonal naive forecasts applied to the ausbeer series
___

# Do they look like white noise (TRUE or FALSE)
beerwn <- ___
Edit and Run Code