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.
hpj(
y,
maxsum = NULL,
lambda = NULL,
xreg = NULL,
ic = c("bic", "hq", "aic", "aicc"),
scl = 1000
)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.
either a numeric vector or a time series object containing the time series to filter;
maximum sum of additional level standard deviations,
if NULL the value is selected automatically on a grid using the specified information criterion (ic);
smoothing constant of the HP filter,
if NULL the value is estimated by maximum likelihood;
matrix of regressors;
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.
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.
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)
Run the code above in your browser using DataLab