First , a simple overview of the data
rGDP <- Quandl("FRED/GDPC1", type="zoo")
str(rGDP)
## 'zooreg' series from 1947 Q1 to 2016 Q4
## Data: num [1:280] 1934 1932 1930 1961 1990 ...
## Index: Class 'yearqtr' num [1:280] 1947 1947 1948 1948 1948 ...
## Frequency: 4
summary(rGDP)
## Index rGDP
## Min. :1947 Min. : 1930
## 1st Qu.:1964 1st Qu.: 3754
## Median :1982 Median : 6552
## Mean :1982 Mean : 7869
## 3rd Qu.:1999 3rd Qu.:12000
## Max. :2017 Max. :16813
head(rGDP)
## 1947 Q1 1947 Q2 1947 Q3 1947 Q4 1948 Q1 1948 Q2
## 1934.5 1932.3 1930.3 1960.7 1989.5 2021.9
tail(rGDP)
## 2015 Q3 2015 Q4 2016 Q1 2016 Q2 2016 Q3 2016 Q4
## 16454.9 16490.7 16525.0 16583.1 16727.0 16813.3
plot(rGDP, xlab="Years", ylab="Gross Domestic Product", main="quarterly Real Gross Domestic Product ")
#Part 1 first Construct the time series with log changes in Real Gross Domestic Product,then split the sample into two parts: first one up to 2008Q4, second one from 2009Q1 onward.
dlrGDP <- diff(log(rGDP))
dlrGDPp1 <- window(dlrGDP, end="2008 Q4")
dlrGDPp2 <- window(dlrGDP, start="2009 Q1")
summary(dlrGDPp1)
## Index dlrGDPp1
## Min. :1947 Min. :-0.026233
## 1st Qu.:1963 1st Qu.: 0.003218
## Median :1978 Median : 0.007941
## Mean :1978 Mean : 0.008176
## 3rd Qu.:1993 3rd Qu.: 0.013436
## Max. :2009 Max. : 0.039083
summary(dlrGDPp2)
## Index dlrGDPp2
## Min. :2009 Min. :-0.013954
## 1st Qu.:2011 1st Qu.: 0.002094
## Median :2013 Median : 0.005109
## Mean :2013 Mean : 0.004460
## 3rd Qu.:2015 3rd Qu.: 0.007359
## Max. :2017 Max. : 0.012108
plot(dlrGDP, xlab="Years", ylab = "Real GDP log Growth rate",main="Real Gross Domestic Product Growth Rate")
plot(dlrGDPp1, xlab="Years", ylab = "Real GDP log Growth rate",main="Real Gross Domestic Product Growth Rate 47-08")
plot(dlrGDPp2, xlab="Years", ylab = "Real GDP log Growth rate",main="Real Gross Domestic Product Growth Rate 09-16")
#Part 2 the ACF and the PACF for the first subsample:
acf(ts(dlrGDPp1), main = "ACF Real Gross Domestic Product")
pacf(ts(dlrGDPp1), main = "PACF Real Gross Domestic Product")
#Part 3 using auto.arima with ic=aicc to find the best model
library(forecast)
mm=auto.arima(dlrGDPp1,ic="aicc",stepwise = FALSE)
tsdiag(mm)
plot.Arima(mm)
mm.f.h <- forecast(mm, length(dlrGDPp2))
fstQ <- 1947.25 # 1947Q2
lstQ <- 2008.75 # 2008Q4
mm.f.rol <- zoo()
for(i in 1:length(dlrGDPp2))
{
y <- window( dlrGDP, start=fstQ+(i-1)/4, end=lstQ+(i-1)/4 )
mm.updt <- auto.arima(y,ic="aicc",stepwise = FALSE)
mm.f.rol <- c(mm.f.rol, forecast(mm.updt, 1)$mean)
}
mm.f.rol <- as.ts(mm.f.rol)
plot(mm.f.h, type="o", pch=16, xlim=c(2005,2016), ylim=c(-0.03,0.03),
main="AutoModel Multistep vs 1 step Forecasts - U.S. Real GDP Growth Rate")
lines(mm.f.h$mean, type="p", pch=16, lty="dashed", col="blue")
lines(dlrGDP, type="o", pch=16, lty="dashed")
lines(mm.f.rol, type="o", pch=16, lty="dashed",col="red")
legend("topleft", c("multistep", "roll"), pch = c(16,16),col=c("blue","red"),lty="dashed")
-The rolling forecasts have better result than the multistep forcast.
accuracy(mm.f.h$mean, dlrGDPp2)
## ME RMSE MAE MPE MAPE
## Test set -0.003490783 0.005284447 0.004223604 -158.8385 233.9624
accuracy(mm.f.rol, dlrGDPp2)
## ME RMSE MAE MPE MAPE
## Test set -0.001794272 0.004906955 0.003889241 -96.14206 166.2151
The auto.arima is a better model than AR(1) shown in slides.