We covered the into to ARIMA. We learned how to fit models to various time series data and do forecasting based on our model.

I chose to look at the data gold. This data is the daily morning gold prices in US dollars from Jan. 1985- Mar. 1989. We learned a new command ‘auto.arima’. This command allows us to find the best fit model for time series. It a function that uses the maximum likelyhood. This is automated in R. This command is very similar to the ‘lm’ command previously used in the class. The command takes a specific univariate arguement. If it’s anything else, the system will shoot out an error.

data(gold)
head(gold)
Time Series:
Start = 1 
End = 6 
Frequency = 1 
[1] 306.25 299.50 303.45 296.75 304.40 298.35
modh<-auto.arima(gold) 
modh
Series: gold 
ARIMA(1,1,2) with drift 

Coefficients:
NaNs produced
          ar1      ma1      ma2   drift
      -0.1628  -0.1744  -0.0552  0.0713
s.e.      NaN      NaN      NaN  0.1151

sigma^2 estimated as 32.47:  log likelihood=-3410.82
AIC=6831.64   AICc=6831.7   BIC=6856.69

Since our data has no seasonal variation, our ARIMA(p,d,q) p is the order (number of time lags) of the autoregressive model, d is the degree of differencing (the number of times the data have had past values subtracted), and q is the order of the moving-average model.

Once we have the model, we can use it to forcast into the future.

Forecasting

forecasth<-forecast(modh,h=3)
forecasth
     Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
1109       383.2157 375.9133 390.5182 372.0476 394.3839
1110       383.2878 374.5272 392.0484 369.8896 396.6859
1111       383.3589 373.3515 393.3664 368.0538 398.6640
plot(forecasth)

forecast1<-forecast(modh,h=100)#100 days forecast
plot(forecast1)

First I forcasted for the next 3 days. The output displays what the point prediction, highs and lows are for each day. R also defaults to display the 80% and 95% level of confidence. We can also plot the model with the forcasted values on the same graph.

The blue line is the point prediction, the dark shaded region is the 80% level of confidence and the light blue is the 95% level of confidence.

I did two different periods of forcasting for comparision. It seems that the longer the forcasting period, the larger the region.

LS0tCnRpdGxlOiAiTGVhcm5pbmcgTG9nIgpvdXRwdXQ6IGh0bWxfbm90ZWJvb2sKLS0tCgpXZSBjb3ZlcmVkIHRoZSBpbnRvIHRvIEFSSU1BLiBXZSBsZWFybmVkIGhvdyB0byBmaX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