hpj: Hodrick-Prescott filter with jumps

View source: R/hpj.R

hpjR Documentation

Hodrick-Prescott filter with jumps

Description

This function is a wrapper for the various Hodrick-Prescott filters with jumps functions. The end user should use this: it is simpler and more flexible than the other functions.

Usage

hpj(
  y,
  maxsum = NULL,
  lambda = NULL,
  xreg = NULL,
  ic = c("bic", "hq", "aic", "aicc"),
  scl = 1000
)

Arguments

y

either a numeric vector or a time series object containing the time series to filter;

maxsum

maximum sum of additional level standard deviations, if NULL the value is selected automatically on a grid using the specified information criterion (ic);

lambda

smoothing constant of the HP filter, if NULL the value is estimated by maximum likelihood;

xreg

matrix of regressors;

ic

string with information criterion for the automatic choice of maxsum: the default is "bic" (simulations show this is the best choice), but also "hq", "aic" and "aicc" are available.

scl

scaling factor for the time series (default is 1000): the time series is rescaled as (y-min(y))/(max(y)-min(y))*scl. This is done since the default starting values for the optimization seem to work well in this scale); If 'scl' is set equal to the string '"original"' the time series is not rescaled.

Value

S3 object of class hpj with the following slots:

  • y: the input time series;

  • maxsum: the maximum sum of additional standard deviations;

  • lambda: the smoothing constant of the HP filter;

  • pars: vector of estimated parameters (sigma_slope, sigma_noise, gamma);

  • hpj: the time series of the HP filter with jumps;

  • hpj_std: the time series of the HP filter with jumps standard deviations;

  • std_devs: vector of additional standard deviations of the level disturbance;

  • breaks: vector of indices of the breaks;

  • xreg: matrix of regressors;

  • df: model's degrees of freedom;

  • loglik: value of the log-likelihood at maximum;

  • ic: vector of information criteria (aic, aicc, bic, hq);

  • opt: the output of the optimization function (nloptr);

  • call: the call to the function.

Examples

set.seed(202311)
n <- 100
mu <- 100*cos(3*pi/n*(1:n)) - ((1:n) > 50)*n - c(rep(0, 50), 1:50)*10
y <- mu + rnorm(n, sd = 20)
hp <- hpj(y, 50)
plot(hp)

jumps documentation built on April 4, 2025, 2:22 a.m.