This book uses the facilities in the forecast package in R (which is loaded automatically whenever you load the fpp2 package). This appendix briefly summarises 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.
Many functions, including
rwf(), produce output in the form of a
forecast object (i.e., an object of class
forecast). This allows other functions (such as
autoplot()) to work consistently across a range of forecasting models.
Objects of class
forecast contain information about the forecasting method, the data used, the point forecasts obtained, prediction intervals, residuals and fitted values. There are several functions designed to work with these objects including
The following list shows all the functions that produce
So far we have used functions which produce a
forecast object directly. But a more common approach, which we will focus on in the rest of the book, will be to fit a model to the data, and then use the
forecast() function to produce forecasts from that model.
forecast() function works with many different types of inputs. It generally takes a time series or time series model as its main argument, and produces forecasts appropriately. It always returns objects of class
If the first argument is of class
ts, it returns forecasts from the automatic ETS algorithm discussed in Chapter 7.
Here is a simple example, applying
forecast() to the
That works quite well if you have no idea what sort of model to use. But by the end of this book, you should not need to use
forecast() in this “blind” fashion. Instead, you will fit a model appropriate to the data, and then use
forecast() to produce forecasts from that model.