log_scale = FALSE,
criterion = "approximate", fmhp = FALSE), and
the frequency "monthly" (lambda = 129600) is added to the
comparisons..default method. A ts keeps its time and
frequency in the results.as_dt = FALSE the filters return lists of class
c("mhp_<filter>", "mhp", "mhp_result", "list") with
print(), summary(), plot(),
ggplot2::autoplot() and as.data.table()
methods; the printed result ends with the sources of the method.mhp_filter() searches 100000 values of lambda
for 200 observations in 1.3 s (6.4 s for 0.1.0), and 3000 values for 500
observations 20 times faster than 0.1.0 (vignette “Validation and
speed”).plot_batch() passed linewidth twice (a
warning) and ignored highlight in the faceted plot.mhp_filter() printed the factor of the
criterion as 1 + 2/(T lambda); the code used, and still
uses, 1 + 2T/lambda (eq. 6 of Choudhary et al. 2014).mhp_batch() and batch_compare() accept
series of different lengths (leading and trailing missing values).fmhp_filter() and fmhp_batch(): the fully
modified HP filter of Hanif, Iqbal and Choudhary (2017), with endogenous
lambda and endogenous linear or quadratic end-point weights; it
reproduces the published MATLAB code (form = "rows", the
default) and offers the penalised least-squares form
(form = "differences") and a fixed lambda
(lambda =).fmhp_compare(): HP, modified HP and fully modified HP
filters compared by the moments of the cycles and the end-point
loss.hp_loss(), hp_gain(),
hp_weights(), hp_schedule(): the end-point
loss of Bloechl (2014), the gain functions, the filter weights and the
end-point schedules of any HP-type filter. The end-point losses of the
HP filter in Tables 3a and 3b of Hanif et al. (2017) are reproduced, and
so are the annual losses of the paper’s own scheme (quadratic weights, k
= 20, alpha = 10) and the weights of its Figure 1a; the quarterly losses
of its scheme are not, because the paper does not report the weights
behind them.mhp_filter(criterion = "exact"): exact generalised
cross-validation (eq. 5 of Choudhary et al. 2014) beside the published
approximation; on the US series it is smallest at lambda = 1, which the
help page explains.mhp_designs(), mhp_simulate(),
fmhp_simulation(): the simulation designs of the 2014 and
2017 papers, simulated trend-plus-cycle series and the power comparison
of the filters. The results of the comparison, for every design, are
shipped and discussed in a vignette; they do not confirm that the fully
modified filter wins in every replicate.mhp_interpret(), mhp_cite(),
mhp_app(): a plain-language interpretation of every result,
the references of every method and a built-in shiny application;
mhp_theme(), mhp_save() (with WebP),
mhp_notation(), mhp_reference().us_macro: quarterly US real GDP, consumption and
investment, 1959 to 2009.This is the first official release of mhpfilter to CRAN.
mhpfilter implements the Modified Hodrick-Prescott (HP) Filter for decomposing macroeconomic time series into trend and cyclical components. The package automatically selects the optimal smoothing parameter λ using generalized cross-validation (GCV), based on the methodology of Choudhary, Hanif & Iqbal (2014).
mhp_filter() - Modified HP filter with automatic λ
selection via GCVhp_filter() - Standard HP filter with fixed λ
parametermhp_compare() - Compare HP vs Modified HP for single
seriesmhp_batch() - Batch processing for multiple time
seriesbatch_compare() - Batch comparison of HP vs Modified
HPautoplot.mhp() - ggplot2-based visualization for mhp
objectsplot_comparison() - Visual comparison of HP vs Modified
HP resultsplot_batch() - Visualization of batch processing
resultsget_lambda() - Extract optimal λ from resultsget_gcv() - Extract GCV value from resultsprint.mhp() - Print method for mhp class objectsdata.table (≥ 1.14.0)collapse (≥ 2.0.0) for fast
statisticskit (≥ 0.0.11) utilitiestidyverse (≥ 2.0.0) and
fastverse (≥ 0.3.0)This implementation is based on:
Choudhary, M.A., Hanif, M.N., & Iqbal, J. (2014). “On smoothing macroeconomic time series using the modified HP filter.” Applied Economics, 46(19), 2205-2214. https://doi.org/10.1080/00036846.2014.896982
Muhammad Yaseen
Postdoctoral Research Fellow
School of Mathematical and Statistical Sciences
Clemson University
Javed Iqbal - State Bank of Pakistan
M. Nadim Hanif - State Bank of Pakistan
# From CRAN (recommended)
install.packages("mhpfilter")
# From GitHub (development version)
devtools::install_github("myaseen208/mhpfilter")MIT License
Please report bugs at: https://github.com/myaseen208/mhpfilter/issues
For more information, visit: https://github.com/myaseen208/mhpfilter