View source: R/detrendfilters.R
hpfilter | R Documentation |
hpfilter
Hodrick-Prescott filter for univariate time series
hpfilter(y, lambda = 1600, type = c("one-sided", "two-sided"))
## S3 method for class 'hpfilter'
plot(x, ...)
## S3 method for class 'hpfilter'
print(x, ..., digits = 3)
y |
univariate time series indexed as |
lambda |
real number giving the smoothing parameter lambda |
type |
should "one-sided" or "two-sided" HP filter be used? One sided runs the two-sided filter consecutively for each t (starting from the third observation) and takes the last value as the trend/cycle component at the time t. |
x |
object of class 'hpfilter' generated by function |
... |
currently not in use. |
digits |
number of digits to be printed. |
@import stats
Decompose univariate time series to cyclical component and trend component with Hodrick-Prescott filter.
This function directly uses the function hp_filter
from the package lpirfs
. Notice that
the first two observations are lost in the one-sided filter.
Returns a class 'hpfilter'
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)
$lambda
:the smoothing parameter lambda
$type
:one-sided or two-sided
$y
:the original series
If the provided series y
is of class ts
, the dates of the decomposed
series will be set accordingly.
plot(hpfilter)
: plot method
print(hpfilter)
: print method
# Log of quarterly industrial production index
data(INDPRO, package="tsfilters")
IPQ <- log(colMeans(matrix(INDPRO, nrow=3)))
IPQ <- ts(IPQ, start=start(INDPRO), frequency=4)
# One-sided
IPQ_hp <- hpfilter(IPQ, lambda=1600, type="one-sided")
plot(IPQ_hp)
IPQ_hp
# Two-sided
IPQ_hp2 <- hpfilter(IPQ, lambda=1600, type="two-sided")
plot(IPQ_hp2)
IPQ_hp2
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.