The autocorrelation function (ACF) is the main method in time series analysis for quantifying the level of correlation between a series and its lags. This method is fairly similar (both mathematically and logically) to the Pearson correlation coefficient, which we saw earlier, and can be formalized with the following expression:
Here, represents the ACF correlation coefficient of the series with its k lag; and n, , and denote the number of observations of the series, the t observation of the series, and the mean, respectively. The acf function from the stats package is R's built-in ACF, which, by default, visualizes the results using a bar plot. Let's use this function to plot the correlation of the USgas series and its first 60 lags (by setting the lag.max argument to 60):
acf(USgas, lag.max = 60)
We will get the following plot:
Each...