mhpfilter: Modified and Fully Modified Hodrick-Prescott Filters

Decomposes macroeconomic time series into trend and cycle with the Hodrick-Prescott (HP) filter and two data-driven versions of it. The modified HP filter of McDermott (1997), assessed by Choudhary, Hanif and Iqbal (2014) <doi:10.1080/00036846.2014.894631>, chooses the smoothing parameter of every series by generalised cross-validation (as described in Coe and McDermott (1997) <doi:10.2307/3867497>). The fully modified HP filter of Hanif, Iqbal and Choudhary (2017, State Bank of Pakistan Working Paper 88) also reduces the end-point bias of the HP filter: it raises the smoothing parameter at the first and last observations, with linear or quadratic weights chosen to minimise the loss of Bloechl (2014, University of Munich Discussion Paper 2014-1). Every filter is a banded linear solve, so the searches are fast; batch processing of many series, comparisons of the filters, the filter weights, gain functions and end-point loss, simulation of trend-plus-cycle series and the power comparison of the paper, 'ggplot2' graphics, a plain-language interpretation of every result and a built-in 'shiny' application.

Version: 1.0.0
Depends: R (≥ 4.2)
Imports: data.table, ggplot2, grDevices, Rcpp, scales, stats, utils
LinkingTo: Rcpp, RcppArmadillo
Suggests: bslib, DT, knitr, magick, pkgload, quarto, ragg, R.rsp, shiny, svglite, testthat (≥ 3.0.0), withr
Published: 2026-11-09
DOI: 10.32614/CRAN.package.mhpfilter
Author: Muhammad Yaseen ORCID iD [aut, cre, cph], Javed Iqbal [ctb] (Original methodology author), M. Nadim Hanif [ctb, cph] (Original methodology author; author of the MATLAB code of the fully modified HP filter), M. Ali Choudhary [ctb] (Original methodology author)
Maintainer: Muhammad Yaseen <myaseen208 at gmail.com>
BugReports: https://github.com/myaseen208/mhpfilter/issues
License: MIT + file LICENSE
Copyright: see file COPYRIGHTS
URL: https://myaseen208.com/mhpfilter/, https://github.com/myaseen208/mhpfilter
NeedsCompilation: yes
Language: en-US
Citation: mhpfilter citation info
Materials: README, NEWS
CRAN checks: mhpfilter results

Documentation:

Reference manual: mhpfilter.html , mhpfilter.pdf
Vignettes: Getting started with mhpfilter (source, R code)
The filters: theory and computation (source, R code)
The modified HP filter (source, R code)
Reproducing the fully modified HP filter (source, R code)
Simulation study (source, R code)
The application (source, R code)
Validation and speed (source, R code)
Getting started with mhpfilter (PDF) (source)
The filters: theory and computation (PDF) (source)
The modified HP filter (PDF) (source)
Reproducing the fully modified HP filter (PDF) (source)
Simulation study (PDF) (source)
The application (PDF) (source)
Validation and speed (PDF) (source)

Downloads:

Package source: mhpfilter_1.0.0.tar.gz
Windows binaries: r-devel: mhpfilter_0.1.0.zip, r-release: mhpfilter_0.1.0.zip, r-oldrel: mhpfilter_0.1.0.zip
macOS binaries: r-release (arm64): mhpfilter_1.0.0.tgz, r-oldrel (arm64): mhpfilter_1.0.0.tgz, r-release (x86_64): mhpfilter_0.1.0.tgz, r-oldrel (x86_64): mhpfilter_0.1.0.tgz
Old sources: mhpfilter archive

Linking:

Please use the canonical form https://CRAN.R-project.org/package=mhpfilter to link to this page.