Time Series - 6.1

In class, we learned about time series. Time series can be described as: \[{y_t} = {TR_t} + {\epsilon_t}\]

y is the value of the time series at time t TR is the trend at time t the epsilon is the error at time t

AutoCorrelation - 6.2

Are residuals correlated through time? If yes, then you have auto(self)correlation.

Positive autocorrelation: positive residual is likely to be followed by another positive residual or negative residual is likely to be followed by another negative residual.

Negative autocorrelation: positive residual is likely to be followed by a negative residual or negative residual is likely to be followed by a positive residual.

First Order Correlation

The error at time t only relates to the error at time t-1 and the error at time t+1.

The first way to look at this is to look at the residuals over time. You can plot that.

The other way is the Durbin Watson statistic. The test is located in the lmtest library so you have to call that first every time.

library(lmtest)
## Warning: package 'lmtest' 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
dwtest(mod)
## 
##  Durbin-Watson test
## 
## data:  mod
## DW = 1.7171, p-value = 0.03464
## alternative hypothesis: true autocorrelation is greater than 0
dwtest(mod, alternative = "less")
## 
##  Durbin-Watson test
## 
## data:  mod
## DW = 1.7171, p-value = 0.9654
## alternative hypothesis: true autocorrelation is less than 0
dwtest(mod, alternative = "two.sided")
## 
##  Durbin-Watson test
## 
## data:  mod
## DW = 1.7171, p-value = 0.06928
## alternative hypothesis: true autocorrelation is not 0

The first output shows that there is positive autocorrelation because the p-value is small. We know it is positive because it says “true autocorrelation is greater than 0”.

The second output shows that there is no negative autocorrelation because the p-value is too big. We know it is negative because it says “true autocorrelation is less than 0”.

The last output shows that there is autocorrelation because the p-value is small. We know that this is positive or negative because it says “true autocorrelation is not 0”.