hpfilter: Hodrick-Prescott filter

View source: R/detrendfilters.R

hpfilterR Documentation

Hodrick-Prescott filter

Description

hpfilter Hodrick-Prescott filter for univariate time series

Usage

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)

Arguments

y

univariate time series indexed as 1,..,T. Can be either a numeric vector or matrix, or a class ts object in which case the dates are correctly passed to the returned components.

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 hpfilter

...

currently not in use.

digits

number of digits to be printed.

Details

@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.

Value

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.

Methods (by generic)

  • plot(hpfilter): plot method

  • print(hpfilter): print method

Examples

 # 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


saviviro/tsfilters documentation built on July 16, 2025, 6:16 p.m.