Decomposes a time series into trend and cycle components using the regression-based filter proposed by Hamilton (2018). The trend is the fitted value from an OLS regression of \(y_{t+h}\) on \((1, y_t, y_{t-1}, \ldots, y_{t-p+1})\), and the cycle is the residual.
Value
A macrofilter object with trend, cycle, data, and meta
components. meta includes h, p, coefficients, and compute_time.
Details
Hamilton (2018) proposes replacing the HP filter with a simple regression: $$y_{t+h} = \beta_0 + \beta_1 y_t + \beta_2 y_{t-1} + \cdots + \beta_p y_{t-p+1} + v_{t+h}$$ The fitted values \(\hat{y}_{t+h}\) define the trend and the residuals \(\hat{v}_{t+h}\) define the cycle.
The first \(h + p - 1\) observations have no computable trend or cycle
and are filled with NA.
The lag matrix is constructed vectorized via embed() and the
regression is solved with stats::lm.fit() for speed.
