Modified Hodrick-Prescott Filter with Optimal Smoothing Parameter Selection
Overview
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.
Initial CRAN Release (2026-02-06)
This is the first official release of **mhpfilter** to CRAN.
Overview
**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).
Core Features
Filtering Functions
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 HP
Visualization Functions
Show all changes in 0.1.0Hide the rest of the changes in 0.1.0
autoplot.mhp()- ggplot2-based visualization for mhp objectsplot_comparison()- Visual comparison of HP vs Modified HP resultsplot_batch()- Visualization of batch processing results
Utility Functions
get_lambda()- Extract optimal λ from resultsget_gcv()- Extract GCV value from resultsprint.mhp()- Print method for mhp class objects
Technical Implementation
High Performance
- Fast C++ implementation using RcppArmadillo for matrix operations
- Optimized grid search algorithm for λ selection
- Efficient memory management for large time series
- Linear scaling for batch processing of multiple series
Modern R Integration
- Full compatibility with
data.table(≥ 1.14.0) - Integration with
collapse(≥ 2.0.0) for fast statistics - Support for
kit(≥ 0.0.11) utilities - Works seamlessly with
tidyverse(≥ 2.0.0) andfastverse(≥ 0.3.0) - ggplot2-based professional visualizations
Documentation
Comprehensive Vignettes
- **Introduction** - Quick start guide with practical examples
- Basic usage and workflow
- Comparison with standard HP filter
- Real-world applications
- **Methodology** - Mathematical theory and derivations
- Standard HP filter formulation
- Generalized cross-validation criterion
- Optimal λ selection procedure
- Performance characteristics
Function Documentation
- Complete roxygen2 documentation for all functions
- Mathematical formulas properly rendered with LaTeX
- Extensive examples with commentary
- Author affiliations and ORCID identifiers
Package Website
- Professional pkgdown site with full documentation
- Download statistics and badges
- Interactive examples and tutorials
- API reference with search functionality
Methodology Reference
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
Authors and Contributors
Package Author and Maintainer
**Muhammad Yaseen**
Postdoctoral Research Fellow
School of Mathematical and Statistical Sciences
Clemson University
Original Methodology Authors
**Javed Iqbal** - State Bank of Pakistan
**M. Nadim Hanif** - State Bank of Pakistan
Installation
```r
From CRAN (recommended)
install.packages("mhpfilter")
From GitHub (development version)
devtools::install_github("myaseen208/mhpfilter")
```
System Requirements
- R ≥ 4.0.0
- C++ compiler for building from source
- Operating systems: Windows, macOS, Linux
Testing and Quality Assurance
- Comprehensive test suite with testthat (≥ 3.0.0)
- Continuous integration via GitHub Actions
- R CMD check passes on all platforms
- CRAN policy compliance verified
- No NOTEs, WARNINGs, or ERRORs
License
MIT License
Bug Reports and Issues
Please report bugs at: https://github.com/myaseen208/mhpfilter/issues
Acknowledgments
- Original methodology: Choudhary, Hanif & Iqbal (2014)
- RcppArmadillo team for excellent C++ integration
- R Core Team for the R statistical computing environment
- CRAN team for review and hosting
---
For more information, visit: https://github.com/myaseen208/mhpfilter
From NEWS.md in the release
Install
Health
- OK13 OK2026-08-05
- NOTE12 OK, 1 NOTE2026-08-01
- OK14 OK2026-04-22
- ERROR13 OK, 1 ERROR2026-04-18
- OK14 OK2026-03-10
Documentation
- Help pages
- 12includes a package overview page
- Examples that run
- 91%10 run in a plain check · 1 only when donttest examples are enabled (R CMD check --as-cran)
- Exported functions with examples
- 100%
- Documented parameters
- 100%
- Return-value docs
- 100%
- Help pages citing references
- 33%
Downloads
Repository
Stars over time
Issues over time
3 development-tooling and community-health practices detected across 2 families in the upstream repository
Checks run against github.com/myaseen208/mhpfilter on 2026-10-18.
Dependencies
Installing mhpfilter adds 21 packages (11 with compiled code, 23 MB of source tarballs). Heaviest: ggplot2 6.0 MB, data.table 5.7 MB, Rcpp 1.8 MB.
Code & Tests
People & History
- RR 4.6.0 released · 2026-04-24
- 0.1.0Latest2026-02-13 · current release
- RR 4.5.0 released · 2025-04-11
Package metadata
- First published
- 2026-02-13
- Total releases
- 1 / 1 yrs
- License
- MIT + file LICENSE OSI
- Minimum R
- ≥ 4.0.0
- Download size
- 443 KB
Cite
Cite this package
Run in R for the authors' entry:
citation("mhpfilter")The package provides a citation file, so citation() returns the authors' own entry.
It points to 10.1080/00036846.2014.894631.
Cite the R Observatory
For a number measured here: a download total, a coverage figure, an archival date.
From data release v2026-10-22, which the citation names so these numbers can be found later. More on citing and the projects behind them.