Book Image

Mastering Data analysis with R

By : Gergely Daróczi
Book Image

Mastering Data analysis with R

By: Gergely Daróczi

Overview of this book

Table of Contents (19 chapters)
Mastering Data Analysis with R
Credits
www.PacktPub.com
Preface

Holt-Winters filtering


We can similarly remove the seasonal effects of a time-series by Holt-Winters filtering. Setting the beta parameter of the HoltWinters function to FALSE will result in a model with exponential smoothing practically suppressing all the outliers; setting the gamma argument to FALSE will result in a non-seasonal model. A quick example:

> nts <- ts(daily$N, frequency = 7)
> fit <- HoltWinters(nts, beta = FALSE, gamma = FALSE)
> plot(fit)

The red line represents the filtered time-series. We can also fit a double or triple exponential model on the time-series by enabling the beta and gamma parameters, resulting in a far better fit:

> fit <- HoltWinters(nts)
> plot(fit)

As this model provides extremely similar values compared to our original data, it can be used to predict future values as well. For this end, we will use the forecast package. By default, the forecast function returns a prediction for the forthcoming 2*frequency values:

> library...