Documentation |
Some time series are decomposable into various trend components. To estimate a trend component without making parametric assumptions, you can consider using a filter.
Filters are functions that turn one time series into another. By appropriate filter selection, certain patterns in the original time series can be clarified or eliminated in the new series. For example, a low-pass filter removes high frequency components, yielding an estimate of the slow-moving trend.
A specific example of a linear filter is the moving average. Consider a time series y_{t}, t = 1,...,N. A symmetric (centered) moving average filter of window length 2q + 1 is given by
$${\widehat{m}}_{t}={\displaystyle \sum _{j=-q}^{q}{b}_{j}{y}_{t+j},}\text{\hspace{0.17em}}\text{\hspace{0.17em}}\text{\hspace{0.17em}}\text{\hspace{0.17em}}\text{\hspace{0.17em}}q<t<N-q.$$
You can choose any weights b_{j} that sum to one. To estimate a slow-moving trend, typically q = 2 is a good choice for quarterly data (a 5-term moving average), or q = 6 for monthly data (a 13-term moving average). Because symmetric moving averages have an odd number of terms, a reasonable choice for the weights is $${b}_{j}=1/4q$$ for j = ±q, and $${b}_{j}=1/2q$$ otherwise. Implement a moving average by convolving a time series with a vector of weights using conv.
You cannot apply a symmetric moving average to the q observations at the beginning and end of the series. This results in observation loss. One option is to use an asymmetric moving average at the ends of the series to preserve all observations.