library("zoo")
## Warning: package 'zoo' was built under R version 3.2.3
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
library("forecast")
## Warning: package 'forecast' was built under R version 3.2.3
## Loading required package: timeDate
## Warning: package 'timeDate' was built under R version 3.2.3
## This is forecast 6.2
library("tseries")
## Warning: package 'tseries' was built under R version 3.2.3

Problem 3

Consider the monthly time series for Consumer Price Index for All Urban Consumers: All Items Less Food and Energy,FRED/CPILFENS.

Introduction:

In this problem, data is analysed about monthly Consumer Price Index for All Urban Consumers without Food and Energy from 1959 to 2015.

DATA:

The data for this problem is collectd from Quand.The Civilian Unemployment Rate used in this anlaysis is monthly data from 1959 to 2015.

cpi_d<- read.csv((url("http://research.stlouisfed.org/fred2/data/PCEPILFE.csv")))

cpi<- ts(cpi_d[,2], start=c(1959,1), frequency = 12)

str(cpi)
##  Time-Series [1:684] from 1959 to 2016: 17.6 17.6 17.6 17.7 17.7 ...
head(cpi)
## [1] 17.597 17.609 17.627 17.670 17.690 17.741
tail(cpi)
## [1] 109.512 109.603 109.794 109.843 110.019 110.066
tsdisplay(cpi, lag.max = 200, xlab=" Years 1959-2015", ylab="Consumer Price Index", main="Consumer Price Index, monthly")

The plot above indicate there is continous increase data set over time. Lets take first difference and check for the stationary of the data. This is done conducting Augmented Dickey-Fuller(ADF) and Kwiatkowski-Phillips-Schmidt-Shin (KPSS) test.

dcpi<-diff(cpi)
tsdisplay(dcpi, lag.max = 200, xlab=" Years 1959-2015", ylab="Consumer Price Index", main="Consumer Price Index, monthly")

adf.test(dcpi)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  dcpi
## Dickey-Fuller = -2.5965, Lag order = 8, p-value = 0.3258
## alternative hypothesis: stationary
kpss.test(dcpi, null="Trend")
## Warning in kpss.test(dcpi, null = "Trend"): p-value smaller than printed p-
## value
## 
##  KPSS Test for Trend Stationarity
## 
## data:  dcpi
## KPSS Trend = 1.4577, Truncation lag parameter = 6, p-value = 0.01

The p-value for KPSS test is 0.01. This suggests, we reject the null hypothesis,which is non-stationary of the data. the p-value of ADF is 0.3258, this suggestes there is some trend in the data. As these two test has shows different results, and the plot shows some trend. Lets do second difference and check for stationarity.

ddcpi<-diff(diff(cpi))
tsdisplay(ddcpi, lag.max = 100, xlab=" Years 1959-2015", ylab="Consumer Price Index", main="Consumer Price Index, monthly")

adf.test(ddcpi)
## Warning in adf.test(ddcpi): p-value smaller than printed p-value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  ddcpi
## Dickey-Fuller = -13.349, Lag order = 8, p-value = 0.01
## alternative hypothesis: stationary
kpss.test(ddcpi, null="Trend")
## Warning in kpss.test(ddcpi, null = "Trend"): p-value greater than printed
## p-value
## 
##  KPSS Test for Trend Stationarity
## 
## data:  ddcpi
## KPSS Trend = 0.0074938, Truncation lag parameter = 6, p-value =
## 0.1

Both test suggest the stationarity of data.

 #split sample - into two parts in order to test the forecasting adequecy of the model
ddcpi_all <- ddcpi
ddcpi_2014 <- window(ddcpi_all, end=c(2014,12))
ddcpi_2015 <- window(ddcpi_all, start=c(2015,1))

Modeling

Assessing the ACF and PACF plots, let try to identity the ARMA model. the is two spike in ACF with some seasonally spike, suggesting MA(2)(1).There is six spike in PACF and seasonal spike is not very significant, suggesting AR(6).This suggests ARMA(6,2)(0,1) model.

arma62_01_12 <- arima(ddcpi_2014, order=c(6,0,2), seasonal=list(order=c(0,0,1),period=12))
tsdisplay(residuals(arma62_01_12))

arma62_01_12
## 
## Call:
## arima(x = ddcpi_2014, order = c(6, 0, 2), seasonal = list(order = c(0, 0, 1), 
##     period = 12))
## 
## Coefficients:
##           ar1      ar2      ar3     ar4      ar5     ar6      ma1      ma2
##       -0.2191  -0.1132  -0.0091  0.0344  -0.0190  0.1429  -0.6518  -0.1794
## s.e.   0.2453   0.0913   0.0962  0.0770   0.0643  0.0593   0.2445   0.1737
##          sma1  intercept
##       -0.0096      1e-04
## s.e.   0.0400      4e-04
## 
## sigma^2 estimated as 0.004266:  log likelihood = 876.65,  aic = -1731.31
tsdiag(arma62_01_12,gof.lag=100)

The above ARMA(6,2)(0,1)_12 model has higher forecasting power for lower lag and the power decrease for higher lag.

Forecasting

The forceasting consist of using the second part of the data to understand the forcasting power of the above model.

par(mfrow=c(1,1))
ARMA.fcast1 <- forecast(arma62_01_12, h=12)
plot(ARMA.fcast1, xlim=c(2000,2015))
lines(ddcpi_2015)

As indicated in the modeling section, the forecasting is good for the time frame choosen for forecast.