HP Filter Using R -


i loading gdp data r fred , using hp filter find cycle component. struggling add date on x axis. tried converting data numeric or dataframe keep getting "cannot coerced" error message. doing wrong?

library(mfilter) library(quantmod) getsymbols('gdp',src='fred') plot(hpfilter(log(gdp),freq = 1600)) 

enter image description here

you can mimic output of plot.hpfilter:

library(mfilter) library(quantmod) getsymbols('gdp',src='fred') hpf <- hpfilter(log(gdp),freq = 1600)  out <- xts(cbind(hpf$x, hpf$trend, hpf$cycle), index(gdp)) colnames(out) <- c("x", "trend", "cycle")  par(mfrow = c(2, 1), mar = c(3, 2, 2, 1)) plot(out[,"x"], t= "n", main = paste(hpf$title, "of", hpf$xname)) lines(out[,"x"], col = "steelblue") lines(out[,"trend"], col = "red") legend("topleft", legend = c(hpf$xname, "trend"), col = c("steelblue", "red"), lty = rep(1, 2), ncol = 2) plot(out[,"cycle"], t = "n", main = "cyclical component (deviations trend)") lines(out[,"cycle"], col = "steelblue") 

enter image description here


Comments

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

Making Empty C++ Project: General exception (Exception from HRESULT:0x80131500) Visual Studio Community 2015 -

How to fix java warning for "The value of the local variable is not used " -