Smoothing time series

Time series decomposition allows us to extract distinct components from time series data. The smoothing technique enables us to forecast the future values of time series data. In this recipe, we introduce how to use the HoltWinters function to smooth time series data.

Getting ready

Ensure you have completed the previous recipe by generating a time series object and storing it in two variables: m and m_ts.

How to do it…

Please perform the following steps to smooth time series data:

  1. First, use HoltWinters to perform Winters exponential smoothing:
    > m.pre <- HoltWinters(m)
    > m.pre
    Holt-Winters exponential smoothing with trend and additive seasonal component.
    
    Call:
    HoltWinters(x = m)
    
    Smoothing parameters:
     alpha: 0.8223689
     beta : ...

Get R for Data Science Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.