Exploring time series forecasting with forecast()

The most logical next step after understanding a time series' features and trends is trying to forecast its future development.

As one would imagine, R provides optimal tools to perform this task.

In this recipe, we will leverage the extremely popular forecast package by Professor Rob J Hyndman. The package provides an always increasing number of tools for performing univariate time series forecasting.

You can find out more on the package on Prof. Hyndman's personal site at http://robjhyndman.com/software/forecast/.

Getting ready

As stated earlier, the only package needed to perform this recipe is the forecast package. We therefore need to install it and load it:

install.packages("forecast")
library(forecast)

How to do it...

  1. Apply the stl() function to the nottem dataset:
    nottem_decomposition <- stl(nottem, s.window = "periodic")
    
  2. Forecast five more years:
    forecast <- forecast(nottem_decomposition,h = 5)
    
  3. Plot the forecasted values:
    plot(forecast(nottem_decomposition))
    

    Let's take a look at the following graph:

    How to do it...

In this plot, you will see a section highlighted in blue. I am sure you have already guessed it; the blue section is exactly what we have been looking for in this recipe, that is, forecasted values.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset