yth_glm
fits a generalized linear model suggested by James D. Hamilton
as a better alternative to the Hodrick-Prescott Filter.
yth_glm(x, h = 8, p = 4, ...)
A univariate xts
object of any
zoo
index class, such as Date
,
yearmon
, or yearqtr
.
For converting objects of type timeSeries
, ts
, irts
,
fts
, matrix
, data.frame
, or zoo
to xts
, please see as.xts
.
An integer
, defining the lookahead period. Defaults to
h = 8
, suggested by Hamilton. The default assumes economic data of
quarterly periodicity with a lookahead period of 2 years. This function is
not limited by the default parameter, and econometricians may change it as required.
An integer
, indicating the number of lags. A default of
p = 4
, suggested by Hamilton, assumes data is of quarterly periodicity.
If data is monthly, one may choose p = 12
or aggregate the series
to quarterly and maintain the default. Econometricians should use this
parameter to accommodate the seasonality of their data.
Additional arguments passed to glm
.
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.
James D. Hamilton. Why You Should Never Use the Hodrick-Prescott Filter. NBER Working Paper No. 23429, Issued in May 2017.
data(GDPC1)
gdp_model <- yth_glm(GDPC1, h = 8, p = 4, family = gaussian)
summary(gdp_model)
#>
#> Call:
#> stats::glm(formula = formula, family = ..1, data = data)
#>
#> Coefficients:
#> Estimate Std. Error t value Pr(>|t|)
#> (Intercept) 195.9049 38.3005 5.115 5.63e-07 ***
#> xt_0 0.7590 0.1321 5.746 2.26e-08 ***
#> xt_1 0.1344 0.1729 0.778 0.437
#> xt_2 0.0431 0.1729 0.249 0.803
#> xt_3 0.1030 0.1327 0.777 0.438
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> (Dispersion parameter for gaussian family taken to be 115351.3)
#>
#> Null deviance: 1.1636e+10 on 302 degrees of freedom
#> Residual deviance: 3.4375e+07 on 298 degrees of freedom
#> (11 observations deleted due to missingness)
#> AIC: 4398.5
#>
#> Number of Fisher Scoring iterations: 2
#>
plot(gdp_model)