hfilter: Filter proposed by Hamilton (2018, doi:10.1162/rest_a_00706)...

View source: R/detrendfilters.R

hfilterR Documentation

Filter proposed by Hamilton (2018, doi:10.1162/rest_a_00706) to separate trend and cycle components of a series.

Description

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.

Usage

hfilter(y, h = 24, p = 12)

## S3 method for class 'hfilter'
plot(x, ...)

## S3 method for class 'hfilter'
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.

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 p > d where d is the order of integration of the series. Hamilton recommends p to be a multiplicative of one year for seasonal data, i.e., for instance p=4 for quarterly data and p=12 monthly data.

x

object of class 'hfilter' generated by function hfilter

...

currently not in use.

digits

number of digits to be printed.

Details

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

Value

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.

Methods (by generic)

  • plot(hfilter): plot method

  • print(hfilter): print method

References

  • J.D. Hamilton. 2018. WHY YOU SHOULD NEVER USE THE HODRICK-PRESCOTT FILTER. The Review of Economics and Statistics, 100(5): 831-843.

Examples

 data(INDPRO, package="tsfilters")
 IP_filtered <- hfilter(log(INDPRO), h=24, p=12)
 IP_filtered
 plot(IP_filtered)

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