The application

Muhammad Yaseen

2026-11-05

1 Abstract

mhp_app() opens an application in the web browser that runs the filters of the package without code: the data, the HP, modified HP and fully modified HP filters, their comparison, the diagnostics of the end-point bias, many series at once and the simulation study. This vignette describes its pages and how it keeps its results reproducible.

2 Starting the application

mhp_app(
    launch.browser = TRUE
  )

The application needs the suggested packages shiny, bslib and DT. magick with WebP support is optional: with it the plots are sent to the browser as WebP images, smaller than the same PNG.

3 The pages

Page What it does
Home what the application does and the order of the pages
Data the us_macro example or a CSV file with one series per column; the series, its frequency and first period, and whether to filter its logarithm
Filter the fully modified HP, modified HP or HP filter with its settings; interpretation, plot, table, printed output and R code
Compare the three filters on the same series: moments of the cycles, the end-point loss and the spread of the cycle at the ends and in the middle
Diagnostics the end-point loss, the gain functions or the filter weights for the smoothing parameters of the last fit
Batch every numeric column of the data, each with its own smoothing parameter
Simulation the power comparison of Hanif et al. (2017) for chosen designs
References the articles behind the methods, as mhp_cite() prints them

Every result page has the same tabs:

The filter page has a further tab, R code, with the code that reproduces the fit outside the application.

The filter page after the fully modified HP filter of US GDP with the default settings:

its plot:

the comparison of the three filters:

and the end-point loss at the chosen smoothing parameters:

The loss on the diagnostics page (0.79) is larger than the loss in the interpretation (0.62): the procedure chooses the weights by their loss at \(\lambda\) of the modified HP filter (683) and then searches \(\lambda\) again (1448), and the loss is reported at the first, as in the MATLAB code. The diagnostics page evaluates it at the second.

4 Reproducibility

For the settings of the screenshots, the R code tab shows:

settings <-
  list(
      source       = "example"
    , freq         = "4"
    , col          = "gdp"
    , start        = 1959
    , start_period = 1
    , logs         = TRUE
    , method       = "fmhp"
    , max_lambda   = 3000
    , k_linear     = 15
    , k_quadratic  = NA
    , schemes      = c("linear", "quadratic")
    , form         = "rows"
    )
cat(mhpfilter:::.mhp_app_code(input = settings))
library(mhpfilter)
data(us_macro)
dat <- us_macro
x <- ts(dat$gdp, start = c(1959, 1), frequency = 4)
fit <-
  fmhp_filter(
      x               = x
    , max_lambda      = 3000
    , k_linear        = 15
    , k_quadratic     = NULL
    , alpha_linear    = seq(from = 0, to = 2000, by = 10)
    , alpha_quadratic = seq(from = 0, to = 2000, by = 5)
    , schemes         = c("linear", "quadratic")
    , form            = "rows"
    , lambda          = NULL
    , log_scale       = TRUE
    , as_dt           = FALSE
    )
fit
plot(x = fit)
mhp_interpret(
    x   = fit
  , top = 3
  )

The filters are deterministic, so the code returns the same numbers as the application.

5 Deploying

mhp_app_object() returns the application object without running it, for a server:

# app.R on a Shiny server
mhpfilter::mhp_app_object()

6 References

Choudhary, M. A., Hanif, M. N. and Iqbal, J. (2014). On smoothing macroeconomic time series using the modified HP filter. Applied Economics, 46(19), 2205–2214.

Hanif, M. N., Iqbal, J. and Choudhary, M. A. (2017). Fully modified HP filter. SBP Working Paper Series, No. 88, State Bank of Pakistan.