This a multipart series aiming to compare and contrast the various Holt Winters implementations in R. We intend to focus more on the practical and applied aspects of the implementations to get a better grip over the behaviour of models and predictions. So to begin with lets look at the ‘HoltWinters()’ function in stats package that comes built-in with R and the ‘hw()’ function in forecast package by Dr. Rob J Hyndman. To install the forecast package, use the following command:
For this analysis, I have chosen to use a time series data available in rdatamarket. The data used is Monthly total number of pigs slaughtered in Victoria. Jan 1980 – August 1995. Since this is available in rdatamarket, we can directly load it in R using the rdatamarket package. So lets load the package and download the data:
This is how the time series appears. On visual inspection, there clearly is a cyclicity and some trend elements involved. As you can see from the pattern, one can conclude that it follows an additive pattern on both seasonal and trend components.
Our approach here is to compare the accuracy prediction capabilities of these functions rather than the closeness of the fit on the training data. Though I have limited my analysis to one type of time series for now, we may have do a similar analysis on other characteristics too, but that will have to wait for some time.
The accuracy measure I have chosen for comparison purposes in this analysis is Mean Absolute Percentage Deviation (MAPE). Our aim here is not to conclude that one function predicts better than the other, but to come to a experiential understanding over how the functions behave depending on the nature of the timeseries. I also would like to point out that the selection of this data for this analysis is purely arbitrary and I encourage you to plug in this code to other time series data you may come across. We have loaded the data and downloaded the packages, So lets begin..