Today in class we covered ARIMA, AutoRegressive Integrated Moving Average model. First we went over AR(p). Which is a movel in which \(y_t\) depends on \(y_{t-1},y_{t-2},...,y_{t-p}\). The equation is \(y_t=\phi_1*y_{t-1}+\phi_2*y_{t-2}+...+\phi_p*y_{t-p}\) where the epsilons are iid with mean 0 and constant variance.
Then we talked about Moving Average models, MA(q). In a moving average model, \(y_t\) depends on \(\epsilon_{t-1}, \epsilon_{t-2},...,\epsilon_{t-q}\). So, \(y_t=\theta_1*\epsilon_{t-1}+\theta_2*\epsilon_{t-2}+...+\theta_q*\epsilon_{t-q}\). where the epsilons are iid with mean 0 and constant variance.
Finally, we talked about ARIMA, which uses both of these methods and if the variance is not constant, it takes the differences between sequential numbers until the variance is constant.
library(astsa)
## Warning: package 'astsa' was built under R version 3.4.3
data(gas)
plot(gas)
So we can see the graph of the price of gas over time. Now that we have the ARIMA model for our data, we can use this to forecast.
library(forecast)
## Warning: package 'forecast' was built under R version 3.4.4
##
## Attaching package: 'forecast'
## The following object is masked _by_ '.GlobalEnv':
##
## gas
## The following object is masked from 'package:astsa':
##
## gas
gasmod<-auto.arima(gas)
gasmod
## Series: gas
## ARIMA(0,1,3)
##
## Coefficients:
## ma1 ma2 ma3
## 0.0510 0.0647 0.1447
## s.e. 0.0426 0.0401 0.0426
##
## sigma^2 estimated as 73.32: log likelihood=-1938.65
## AIC=3885.29 AICc=3885.37 BIC=3902.49
We can see here that our model has no AR component, 1st order difference component, and 3 MA components. We can now graph this ARIMA model
gasforecast<-forecast(gasmod, h=10)
gasforecast
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 2010.481 189.3976 178.4237 200.3715 172.6145 206.1807
## 2010.500 187.5015 171.5810 203.4219 163.1533 211.8496
## 2010.519 184.9345 164.8505 205.0184 154.2187 215.6502
## 2010.538 184.9345 160.5483 209.3207 147.6390 222.2299
## 2010.558 184.9345 156.8986 212.9703 142.0574 227.8116
## 2010.577 184.9345 153.6722 216.1967 137.1230 232.7460
## 2010.596 184.9345 150.7489 219.1200 132.6522 237.2167
## 2010.615 184.9345 148.0567 221.8123 128.5348 241.3342
## 2010.635 184.9345 145.5480 224.3209 124.6981 245.1709
## 2010.654 184.9345 143.1898 226.6791 121.0916 248.7774
plot(gasforecast)
Forecasts are difficult because predicting the future is so difficult. This is why the prediction intervals are so large. The larger our forecast is, the larger the prediction interval will be.
The intro into ARIMA today was extremely helpful. In general, ARIMA is a good way to smooth out our data and get more accurate forecasts, even though forecasts are extremely difficult.