Package: mhpfilter 0.1.0

Muhammad Yaseen

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-x86_64)mhpfilter_0.1.0.zip(r-4.7-arm64)mhpfilter_0.1.0.zip(r-4.6-x86_64)mhpfilter_0.1.0.zip(r-4.6-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://cran.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

3.00 score 1 stars 227 downloads 9 exports 21 dependencies

Last updated from:c73a77f5d8. Checks:10 OK. Indexed: no.

TargetResultTimeFilesSyslog
linux-devel-arm64OK145
linux-devel-x86_64OK176
source / vignettesOK236
linux-release-arm64OK134
linux-release-x86_64OK138
windows-devel-arm64OK230
windows-devel-x86_64OK193
windows-release-arm64OK242
windows-release-x86_64OK141
wasm-releaseOK121

Exports:batch_compareget_gcvget_lambdahp_filtermhp_batchmhp_comparemhp_filterplot_batchplot_comparison

Dependencies:clicollapsecpp11data.tablefarverggplot2gluegtableisobandlabelinglifecycleR6RColorBrewerRcppRcppArmadillorlangS7scalesvctrsviridisLitewithr

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-13
Started: 2026-02-13

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-13