Skip to content

mhpfilter

0.1.0Package record

Modified Hodrick-Prescott Filter with Optimal Smoothing Parameter Selection

0packages depend
1.8Kdownloads / year
–test coverage
13/13flavors OK

Overview

About

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.

Changes in 0.1.0

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 GCV
  • hp_filter() - Standard HP filter with fixed λ parameter
  • mhp_compare() - Compare HP vs Modified HP for single series
  • mhp_batch() - Batch processing for multiple time series
  • batch_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 objects
  • plot_comparison() - Visual comparison of HP vs Modified HP results
  • plot_batch() - Visualization of batch processing results

Utility Functions

  • get_lambda() - Extract optimal λ from results
  • get_gcv() - Extract GCV value from results
  • print.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) and fastverse (≥ 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

CRAN checks
13OK
Slowest check: 5.8 min · r-oldrel-macos-x86_64
Status changes
  • OK13 OK2026-08-05
  • NOTE12 OK, 1 NOTE2026-08-01
  • OK14 OK2026-04-22
  • ERROR13 OK, 1 ERROR2026-04-18
  • OK14 OK2026-03-10
Advisories

none known

Documentation

In release 0.1.0
READMEYes · 339 wordsVignettesYes · 2 · dynamicNEWSYes · 67% structured · mentions 0.1.0Citation fileYes · cites a publicationWebsiteYes · pkgdown
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

1.8K
CRAN downloads in the past year
Rank #21,921 · ~5/day · ~150/mo
Daily download trend is not available in this view yet.
21930 days
60490 days
1.8K1 year
Compare downloads with other packages →
Also on215 r2u6 autocran

Repository

2Stars
0Forks
1Open issues
0Open PRs
0Releases
10Commits
1Commit identities
10 commits · Last activity 2026-02-13 · 0% stars, 30d
Responsiveness
not measured

Stars over time

2026-02-13 · 22026-07-07 · 2
PracticesBeta

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.

Docs source (2)
pkgdown

GitHub Pages site last deployed 2026-02-13

pkgdown site last built 2026-02-13

CRAN release process (1)
CRAN-SUBMISSION
How this is detected·Detection ruleset v3 (2026-09-26)

Dependencies

Declared dependencies
12 external dependencies (excludes base and recommended)

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.

Depends (1)
R >= 4.0.0
LinkingTo (2)
Enhances (0)
none
Reverse dependencies
0direct
0indirect

Nothing depends on this yet.

People & History

People (3)
Author, Maintainer since 0.1.0 (2026)
Contributor
Original methodology author
Contributor
Original methodology author
Releases (1)
  • R
    R 4.6.0 released · 2026-04-24
  • 0.1.0Latest
    2026-02-13 · current release
  • R
    R 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.

APA

Balamuta, J. J. (2026). R Observatory: Metrics for mhpfilter version 0.1.0 [Data set]. HJJB, LLC. Data release v2026-10-22. https://doi.org/10.5281/zenodo.21843040

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.

Report a problem with this page →

Privacy choices

These apply to this browser and are stored on this device only. Nothing about your choice is sent to us.

Read the privacy policy