Description Usage Arguments Details Value References See Also Examples
yth_filter
returns an xts
object containing user defined
combinations of the original, trend, cycle, and random walk series.
1 | yth_filter(x, h = 8, p = 4, output = c("x", "trend", "cycle", "random"), ...)
|
x |
A univariate |
h |
An |
p |
An |
output |
A |
... |
other arguments passed to the function |
For time series of quarterly periodicity, Hamilton suggests parameters of h = 8 and p = 4, or an AR(4) process, additionally lagged by 8 lookahead periods. Econometricians may explore variations of h. However, p is designed to correspond with the seasonality of a given periodicity and should be matched accordingly.
y_{t+h} = β_0 + β_1 y_t + β_2 y_{t-1} + β_3 y_{t-2} + β_4 y_{t-3} + v_{t+h}
\hat{v}_{t+h} = y_{t+h} - \hat{β}_0 + \hat{β}_1 y_t + \hat{β}_2 y_{t-1} + \hat{β}_3 y_{t-2} + \hat{β}_4 y_{t-3}
Which can be rewritten as:
y_{t} = β_0 + β_1 y_{t-8} + β_2 y_{t-9} + β_3 y_{t-10} + β_4 y_{t-11} + v_{t}
\hat{v}_{t} = y_{t} - \hat{β}_0 + \hat{β}_1 y_{t-8} + \hat{β}_2 y_{t-9} + \hat{β}_3 y_{t-10} + \hat{β}_4 y_{t-11}
An xts
object defined by the output
parameter.
James D. Hamilton. Why You Should Never Use the Hodrick-Prescott Filter. NBER Working Paper No. 23429, Issued in May 2017.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | data(GDPC1)
gdp_filter <- yth_filter(100*log(GDPC1), h = 8, p = 4)
knitr::kable(head(gdp_filter, 15), align = 'l')
#---------------------------------------------------------------------------#
data(PAYEMS)
log_Employment <- 100*log(xts::to.quarterly(PAYEMS["1947/2016-6"], OHLC = FALSE))
employ_trend <- yth_filter(log_Employment, h = 8, p = 4, output = c("x", "trend"))
plot(employ_trend, grid.col = "white", legend.loc = "topleft",
main = "Log of Employment and trend")
#----------------------------------------------------------------------------#
quarterly_data <- 100*log(merge(GDPC1, PCECC96, GPDIC1, EXPGSC1, IMPGSC1, GCEC1, GDPDEF))
cycle <- do.call(merge, lapply(quarterly_data, yth_filter, output = "cycle"))
random <- do.call(merge, lapply(quarterly_data, yth_filter, output = "random"))
cycle.sd <- t(data.frame(lapply(cycle, sd, na.rm = TRUE)))
GDP.cor <- t(data.frame(lapply(cycle, cor, cycle[,1], use = "complete.obs")))
random.sd <- t(data.frame(lapply(random, sd, na.rm = TRUE)))
random.cor <- t(data.frame(lapply(random, cor, random[,1], use = "complete.obs")))
my_table_2 <- round(data.frame(cbind(cycle.sd, GDP.cor, random.sd, random.cor)), 2)
names(my_table_2) <- names(Hamilton_table_2)[1:4]
knitr::kable(my_table_2, align = 'l')
|
Loading required package: xts
Loading required package: zoo
Attaching package: ‘zoo’
The following objects are masked from ‘package:base’:
as.Date, as.Date.numeric
|GDPC1 |GDPC1.trend |GDPC1.cycle |GDPC1.random |
|:--------|:-----------|:-----------|:------------|
|761.7298 |NA |NA |NA |
|761.4627 |NA |NA |NA |
|761.2560 |NA |NA |NA |
|762.8081 |NA |NA |NA |
|764.3012 |NA |NA |NA |
|765.9384 |NA |NA |NA |
|766.5096 |NA |NA |NA |
|766.6213 |NA |NA |NA |
|765.2338 |NA |NA |3.503988 |
|764.8921 |NA |NA |3.429356 |
|765.9192 |NA |NA |4.663188 |
|765.0764 |772.3598 |-7.2833996 |2.268271 |
|768.9313 |773.5218 |-4.5905800 |4.630074 |
|771.9355 |774.6608 |-2.7252604 |5.997144 |
|775.7271 |775.0227 |0.7044108 |9.217473 |
| |cycle.sd |gdp.cor |random.sd |gdp.rand.cor |
|:-------------|:--------|:-------|:---------|:------------|
|GDPC1.cycle |3.28 |1.00 |3.57 |1.00 |
|PCECC96.cycle |2.77 |0.78 |2.95 |0.82 |
|GPDIC1.cycle |12.80 |0.83 |13.31 |0.78 |
|EXPGSC1.cycle |10.58 |0.33 |11.13 |0.31 |
|IMPGSC1.cycle |9.50 |0.76 |9.71 |0.75 |
|GCEC1.cycle |7.00 |0.32 |8.38 |0.38 |
|GDPDEF.cycle |2.93 |0.03 |4.07 |-0.12 |
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.