Class

In class we discussed ARIMA models. ARIMA models have three components. First, ARIMA models are auto regressive, meaning they use past data to predict the new data point. Secondly, ARIMA models use differencing. This means that the model uses the differences between points instead of the actual points. Lastly, ARIMA uses moving average. Moving average uses the error terms as predictors.

ARIMA

For this example we will be using the jj data which is the Johnson and Johnson Quarterly Earnings per Share. We also need to load all of the packages to use ARIMA commands in R.

data(jj)
## Warning in data(jj): data set 'jj' not found
library(astsa)
## Warning: package 'astsa' was built under R version 3.4.3
library(quantmod)
## Warning: package 'quantmod' was built under R version 3.4.4
## Loading required package: xts
## Warning: package 'xts' was built under R version 3.4.4
## Loading required package: zoo
## Warning: package 'zoo' was built under R version 3.4.4
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## Loading required package: TTR
## Warning: package 'TTR' was built under R version 3.4.3
## Version 0.4-0 included new data defaults. See ?getSymbols.
library(timeSeries)
## Warning: package 'timeSeries' was built under R version 3.4.4
## Loading required package: timeDate
## Warning: package 'timeDate' was built under R version 3.4.4
## 
## Attaching package: 'timeSeries'
## The following object is masked from 'package:zoo':
## 
##     time<-
library(tseries)
## Warning: package 'tseries' was built under R version 3.4.4
library(forecast)
## Warning: package 'forecast' was built under R version 3.4.4
## 
## Attaching package: 'forecast'
## The following object is masked from 'package:astsa':
## 
##     gas
library(xts)

Our first step is to make a model of the jj data using the auto.arima() function.

mod<-auto.arima(jj)
mod
## Series: jj 
## ARIMA(1,1,2)(0,1,0)[4] 
## 
## Coefficients:
##           ar1      ma1      ma2
##       -0.7921  -0.0970  -0.3945
## s.e.   0.1396   0.1802   0.1580
## 
## sigma^2 estimated as 0.1834:  log likelihood=-44.07
## AIC=96.14   AICc=96.68   BIC=105.61

Next we want to forecast the model into the future with the forecast(model, h). In this example I set h=15 to predict 15 future points.

mycast<-forecast(mod, h=15)

Lastly, we can see where these predicted points land on the graph and visually see if the predicted points make sense.

plot(mycast)

As you can see the blue line is our predicted values and the light blue around it is our 80% prediction interval. The even lighter blue outside that is our 95% prediction interval. As you can see the prediction intervals get very wide right away. This is because it is hard to predict into the future so there is a wide prediction interval.