View source: R/detrendfilters.R
hfilter | R Documentation |
hfilter
separates trend and cycle components of univariate time series
using the method proposed by Hamilton (2018, doi:10.1162/rest_a_00706) based on linear
projections.
hfilter(y, h = 24, p = 12)
## S3 method for class 'hfilter'
plot(x, ...)
## S3 method for class 'hfilter'
print(x, ..., digits = 3)
y |
univariate time series indexed as |
h |
an integer value giving the horizon of the linear projection. Hamilton recommends two years, i.e., 8 for quarterly data and 24 for monthly data. |
p |
the number of lags (including the zero lag) used in the linear projection. Should be
chosen so that |
x |
object of class 'hfilter' generated by function |
... |
currently not in use. |
digits |
number of digits to be printed. |
The first p + h - 1
observations of the series are required to obtain the cycle component
at time p + h
(= first time point of the series). For more details, see the paper
by Hamilton (2018).
Returns a class 'hfilter'
object containing the following:
$cycle
:the cyclical component of the series
$trend
:the trend component of the series
$total
:trend + cyclical (shorter than the original series)
$beta
:the OLS coefficients
$y
:the original series
$h
:the horizon used
$p
:the number of lags (including the zero lag) used
If the provided series y
is of class ts
, the dates of the detrended
series will be set accordingly.
plot(hfilter)
: plot method
print(hfilter)
: print method
J.D. Hamilton. 2018. WHY YOU SHOULD NEVER USE THE HODRICK-PRESCOTT FILTER. The Review of Economics and Statistics, 100(5): 831-843.
data(INDPRO, package="tsfilters")
IP_filtered <- hfilter(log(INDPRO), h=24, p=12)
IP_filtered
plot(IP_filtered)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.