In this problem we test “Consumer Price Index for All Urban Consumers: All Items Less Food and Energy” for nonstationarity using ADF and KPPS tests. Let’s first import and plot the data:
library(Quandl)
## Loading required package: xts
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
Quandl.api_key("t1BuHRnYBbU8N1_qwu5b")
CPI <- Quandl("FRED/CPILFENS", type="zoo")
str(CPI)
## 'zooreg' series from Jan 1957 to Nov 2015
## Data: num [1:707] 28.5 28.5 28.7 28.8 28.8 28.9 28.9 29 29.1 29.2 ...
## Index: Class 'yearmon' num [1:707] 1957 1957 1957 1957 1957 ...
## Frequency: 12
head(CPI)
## Jan 1957 Feb 1957 Mar 1957 Apr 1957 May 1957 Jun 1957
## 28.5 28.5 28.7 28.8 28.8 28.9
tail(CPI)
## Jun 2015 Jul 2015 Aug 2015 Sep 2015 Oct 2015 Nov 2015
## 242.354 242.436 242.651 243.359 243.985 244.075
plot(CPI, xlab="", ylab="", main="Consumer Price Index for All Urban Consumers (CPI)")
And let’s estimate and plot the difference and log difference of series:
dCPI<-diff(CPI)
lCPI<-log(CPI)
dlCPI<-diff(CPI)
par(mfrow=c(1,2))
plot(dlCPI,xlab="",ylab="",main="First Differance of CPI (dCPI)")
plot(dlCPI,xlab="",ylab="",main="Log Differance of CPI (dlCPI)")
And ADF and KPSS tests results are:
ADF and KPSS tests are:
library(tseries)
adf.test(dCPI)
## Warning in adf.test(dCPI): p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: dCPI
## Dickey-Fuller = -5.3713, Lag order = 8, p-value = 0.01
## alternative hypothesis: stationary
kpss.test(dCPI)
## Warning in kpss.test(dCPI): p-value smaller than printed p-value
##
## KPSS Test for Level Stationarity
##
## data: dCPI
## KPSS Level = 3.2663, Truncation lag parameter = 6, p-value = 0.01
adf.test(dlCPI)
## Warning in adf.test(dlCPI): p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: dlCPI
## Dickey-Fuller = -5.3713, Lag order = 8, p-value = 0.01
## alternative hypothesis: stationary
kpss.test(dlCPI)
## Warning in kpss.test(dlCPI): p-value smaller than printed p-value
##
## KPSS Test for Level Stationarity
##
## data: dlCPI
## KPSS Level = 3.2663, Truncation lag parameter = 6, p-value = 0.01
At 5% level we can reject the null hypothesis of non-stationarity. Both first difference and log difference are giving similar results. Now let’s derive ACF and PACF, necessary for forecasting:
par(mfrow=c(2,2))
acf(as.data.frame(dCPI),type='correlation',lag=24, main="dCPI")
acf(as.data.frame(dCPI),type='partial',lag=24, main="dCPI")
acf(as.data.frame(dlCPI),type='correlation',lag=24, main="dlCPI")
acf(as.data.frame(dlCPI),type='partial',lag=24, main="dlCPI")
Based on ACF and PACF, I’d like to estimate ARiMA model of:
m1 <- arima(dCPI,order=c(4,1,2),seasonal=list(order=c(1,0,1),period=12))
m1
##
## Call:
## arima(x = dCPI, order = c(4, 1, 2), seasonal = list(order = c(1, 0, 1), period = 12))
##
## Coefficients:
## ar1 ar2 ar3 ar4 ma1 ma2 sar1
## -0.1140 -0.0068 -0.0929 -0.1784 -0.5338 -0.2266 0.9733
## s.e. 0.1926 0.0697 0.0454 0.0429 0.1940 0.1750 0.0091
## sma1
## -0.7203
## s.e. 0.0310
##
## sigma^2 estimated as 0.0275: log likelihood = 258.17, aic = -498.34
tsdiag(m1,gof.lag=12)
Forecasting
library(forecast)
## Loading required package: timeDate
## This is forecast 6.2
m1.fcast <- forecast(m1, h=24)
plot(m1.fcast, xlim=c(2014, 2017))