Package: mhpfilter 0.1.0

mhpfilter: Modified Hodrick-Prescott Filter with Optimal Smoothing Parameter Selection

High-performance implementation of the Modified Hodrick-Prescott (HP) Filter for decomposing macroeconomic time series into trend and cyclical components. Based on the methodology of Choudhary, Hanif and Iqbal (2014) <doi:10.1080/00036846.2014.894631> "On smoothing macroeconomic time series using the modified HP filter", which uses generalized cross-validation (GCV) to automatically select the optimal smoothing parameter lambda, following McDermott (1997) "An automatic method for choosing the smoothing parameter in the HP filter" (as described in Coe and McDermott (1997) <doi:10.2307/3867497>). Unlike the standard HP filter that uses fixed lambda values (1600 for quarterly, 100 for annual data), this package estimates series-specific lambda values that minimize the GCV criterion. Implements efficient C++ routines via 'RcppArmadillo' for fast computation, supports batch processing of multiple series, and provides comprehensive visualization tools using 'ggplot2'. Particularly useful for cross-country macroeconomic comparisons, business cycle analysis, and when the appropriate smoothing parameter is uncertain.

Authors:Muhammad Yaseen [aut, cre], Javed Iqbal [ctb], M. Nadim Hanif [ctb]

mhpfilter_0.1.0.tar.gz
mhpfilter_0.1.0.zip(r-4.7)mhpfilter_0.1.0.zip(r-4.6)mhpfilter_0.1.0.zip(r-4.5)
mhpfilter_0.1.0.tgz(r-4.6-x86_64)mhpfilter_0.1.0.tgz(r-4.6-arm64)mhpfilter_0.1.0.tgz(r-4.5-x86_64)mhpfilter_0.1.0.tgz(r-4.5-arm64)
mhpfilter_0.1.0.tar.gz(r-4.7-arm64)mhpfilter_0.1.0.tar.gz(r-4.7-x86_64)mhpfilter_0.1.0.tar.gz(r-4.6-arm64)mhpfilter_0.1.0.tar.gz(r-4.6-x86_64)
mhpfilter_0.1.0.tgz(r-4.6-emscripten)
manual.pdf |manual.html
DESCRIPTION |NEWS
card.svg |card.png
mhpfilter/json (API)

# Install 'mhpfilter' in R:
install.packages('mhpfilter', repos = c('https://myaseen208.r-universe.dev', 'https://cloud.r-project.org'))

Bug tracker:https://github.com/myaseen208/mhpfilter/issues

Pkgdown/docs site:https://myaseen208.com

Uses libs:
  • openblas– Optimized BLAS
  • c++– GNU Standard C++ Library v3

On CRAN:

Conda:

openblascpp

4.60 score 2 stars 139 downloads 9 exports 21 dependencies

Last updated from:308f6886e1. Checks:13 OK. Indexed: yes.

TargetResultTimeFilesSyslog
linux-devel-arm64OK155
linux-devel-x86_64OK170
source / vignettesOK221
linux-release-arm64OK155
linux-release-x86_64OK172
macos-release-arm64OK123
macos-release-x86_64OK281
macos-oldrel-arm64OK106
macos-oldrel-x86_64OK224
windows-develOK146
windows-releaseOK134
windows-oldrelOK126
wasm-releaseOK130

Exports:batch_compareget_gcvget_lambdahp_filtermhp_batchmhp_comparemhp_filterplot_batchplot_comparison

Dependencies:clicollapsecpp11data.tablefarverggplot2gluegtableisobandlabelinglifecycleR6RColorBrewerRcppRcppArmadillorlangS7scalesvctrsviridisLitewithr

Modified HP Filter: Theory and Methodology
Introduction | 1. The Standard HP Filter | 1.1 Problem Formulation | 1.2 Matrix Formulation | 1.3 The Problem with Fixed Lambda | 2. The Modified HP Filter | 2.1 Cross-Validation Approach | 2.2 Generalized Cross-Validation | 2.3 Algorithm | 3. Why Modified HP Filter Works Better | 3.1 Simulation Evidence | 3.2 Empirical Evidence | 4. Theoretical Justification | 4.1 Why Cross-Validation? | 4.2 Relationship to Signal Extraction | 4.3 Connection to Spline Smoothing | 5. Practical Recommendations | 5.1 When to Use Modified HP Filter | 5.2 Choosing max_lambda | 5.3 Interpreting Results | 6. Mathematical Appendix | 6.1 Derivation of HP Filter Solution | 6.2 Structure of Matrix A | 6.3 GCV Approximation | References

Last update: 2026-02-13
Started: 2026-02-06

Introduction to mhpfilter
Overview | Why Modified HP Filter? | Installation | Quick Start | Example 1: GDP-like Series | Visualization with autoplot | Comparison with Standard HP Filter | Example 2: Why Fixed Lambda Matters | Visual Comparison | Key Insights from Comparison | Batch Processing: Multi-Country Analysis | Example 3: Cross-Country GDP Comparison | Visualizing Cross-Country Cycles | Highlighting Specific Countries | Batch Comparison with Standard HP | Example 4: Real Business Cycle Analysis | Cyclical Properties Visualization | Example 5: Sensitivity to Lambda | Performance Tips | Choosing max_lambda | Batch Processing Efficiency | Summary and Recommendations | When to Use Modified HP Filter | Key Takeaways | References | See Also

Last update: 2026-02-06
Started: 2026-02-06