What we learned

We covered ARIMA models today in class. These allow us to make predictions on time series. This is similar to a regression model for non time series data. These models use autoregression which means that the point is dependent on the point before it. There are also moving average which means that the term will be dependent on the error of the term before it.

Making a model

We will use the globabl temperature data set to predict the next 10 time periods of global temperature.

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
## 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
library(xts)
library(astsa)
## 
## Attaching package: 'astsa'
## The following object is masked from 'package:forecast':
## 
##     gas
data(globtemp)

We will use the auto.arima function

timemod<-auto.arima(globtemp)

Now that we have a model we can predict or forecast to the future. We will use the forecast function and call it tempfore. h is how many time periods we want to forecast we will use 10 but this may be too large to be accurate.

tempfore<-forecast(timemod, h = 10)
tempfore
##      Point Forecast     Lo 80     Hi 80     Lo 95    Hi 95
## 2016      0.8031838 0.6743294 0.9320383 0.6061180 1.000250
## 2017      0.7841177 0.6346035 0.9336320 0.5554555 1.012780
## 2018      0.7819961 0.6219774 0.9420147 0.5372687 1.026723
## 2019      0.7858872 0.6181356 0.9536388 0.5293333 1.042441
## 2020      0.7919120 0.6174348 0.9663893 0.5250721 1.058752
## 2021      0.7986940 0.6179620 0.9794260 0.5222882 1.075100
## 2022      0.8057447 0.6190423 0.9924470 0.5202080 1.091281
## 2023      0.8128907 0.6204288 1.0053525 0.5185456 1.107236
## 2024      0.8200705 0.6220253 1.0181156 0.5171866 1.122954
## 2025      0.8272623 0.6237901 1.0307345 0.5160785 1.138446

This gives us intervals of all of the points forcasted but it would be much more helpful to plot this.

plot(tempfore)

We can see this is probably not a very good forcast but it gives us an idea. the lighter are is the 80% confidence while the darker is 95%.

This is similar to linear regression but allows us to more accurately predict time series.