2.10 The forecast package in R

This book uses the facilities in the forecast package in R (which is automatically loaded whenever you load the fpp package). This appendix briefly summarizes some of the features of the package. Please refer to the help files for individual functions to learn more, and to see some examples of their use.

Functions that output a forecast object:

  • meanf()
  • naive(), snaive()
  • rwf()
  • croston()
  • stlf()
  • ses()
  • holt(), hw()
  • splinef()
  • thetaf()
  • forecast()

The forecast class contains

  • Original series
  • Point forecasts
  • Prediction interval
  • Forecasting method used
  • Residuals and in-sample one-step forecasts

forecast() function

  • Takes a time series or time series model as its main argument
  • If first argument is class ts, returns forecasts from automatic ETS algorithm.
  • Methods for objects of class Arima, ar, HoltWinters, StructTS, etc.
  • Output as class forecast.
R code
> forecast(ausbeer)

        Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
2008 Q4          480.9 458.8 502.9 446.0 514.3
2009 Q1          423.1 403.2 442.7 392.7 453.0
2009 Q2          386.0 367.8 404.6 357.8 414.8
2009 Q3          402.7 382.7 423.3 372.6 433.5
2009 Q4          481.4 455.4 508.2 442.1 523.3
2010 Q1          423.5 398.6 449.1 386.3 462.7
2010 Q2          386.3 362.9 410.6 350.5 423.0
2010 Q3          403.0 377.8 429.6 363.9 444.5