Learn R Programming

jumps (version 1.0)

hpfj: HP filter with automatic jumps detection.

Description

This is the lower-level function for the HP filter with jumps. The user should use the hpj function instead, unless in need of more control and speed. The function estimates the HP filter with jumps. Jumps happen contextually in the level and in the slope: the standard deviation of the slope disturbance is \(\gamma\) times the standard deviation of the level disturbance at time \(t\). The HP smoothing parameter \(\lambda\) is estimated via MLE (assuming normally distributed disturbances) as in Wahba (1978): \(\lambda = \sigma^2_\varepsilon / \sigma^2_\zeta\).

Usage

hpfj(y, maxsum = sd(y), edf = TRUE, parinit = NULL)

Value

list with the following slots:

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

  • nobs: number of observations

  • df: number of estimated parameters (model's degrees of freedom)

  • loglik: value of the log-likelihood at maximum

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

  • smoothed_level: vector with smoothed level with jumps (hp filter with jumps)

  • var_smoothed_level: variance of the smoothed level

Arguments

y

vector with the time series;

maxsum

maximum sum of additional level standard deviations;

edf

boolean if TRUE computes effective degrees of freedom otherwise computes the number of degrees of freedom in the LASSO-regression way;

parinit

either NULL or vector of 3+n parameters with starting values for the optimizer; the order of the parameters is sd(slope disturbnce), sd(observatio noise), square root of gamma, n additional std deviations for the slope.

References

Whaba (1978) "Improper priors, spline smoothing and the problem of guarding against model errors in regression", *Journal of the Royal Statistical Society. Series B*, Vol. 40(3), pp. 364-372. DOI:10.1111/j.2517-6161.1978.tb01050.x

Examples

Run this code
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)
plot(y, type = "l")
lines(mu, col = "blue")
hp <- hpfj(y, 60)
lines(hp$smoothed_level, col = "red")

Run the code above in your browser using DataLab