AdaemmerP / lpirfs

40 stars 21 forks source link

Bug in hp_filter #3

Closed AdaemmerP closed 5 years ago

AdaemmerP commented 5 years ago

There is a bug in the hp_filter function. The value "lambda" refers to the cut-off frequency of the Hodrick-Prescott filter. To obtain values for lambda = (6, 1600, 129600), you have to type in (1, 4, 12), respectively.

AdaemmerP commented 5 years ago

It's no bug! hp_filter() from lpirfs yields identical results as hpfilter() from mFilter. It was a mixup with some inputs. Results can be verified in R by, for example, running:

# Load libraries library(lpirfs) library(mFilter) library(testthat) library(microbenchmark)

# Use GDP series data_set <- interest_rules_var_data$GDP_gap

# hpfilter() from mFilter hp1 <- hpfilter(as.ts(data_set), freq = 1600, type = "lambda") head(hp1$trend)

# hp_filter() from lpirfs hp2 <- hp_filter(as.matrix(data_set), 1600) head(hp2[[2]])

# Verify results testthat::expect_equal(as.numeric(hp1$cycle), as.numeric(hp2[[1]]), tolerance = 0.1^10) testthat::expect_equal(as.numeric(hp1$trend), as.numeric(hp2[[2]]), tolerance = 0.1^10)

# Compare performance data_set_ts <- as.ts(data_set) data_set_mat <- as.matrix(data_set)

microbenchmark( hpfilter(data_set_ts, freq = 1600, type = "lambda"), hp_filter(data_set_mat, 1600) )