Definition of Autocorrelation

Given a time series x_{1}, x_{2}, x_{3}, \cdots, x_{t}, \cdots, x_{T} , where x_{t}  denotes the observation at time , the time series is said to show autocorrelation if there is correlation between the lagged values of the time series. The autocorrelation coefficient r_{1} is the correlation coefficient of lag 1, i.e. it measures the linear relationship between x_{t}  and x_{t-1} for all time t . In general, the autocorrelation coefficient r_{i} is the correlation coffecient of the time series lagged by i, and it measures the linear relationship between x_t and x_{t-i}.


Example of an Auto Correlated Time Series

Let's create a periodic time series data set with some errors thrown in:

Now let's look at this newly created dataset:


It does look periodic peppered with some errors, so it should work for our purpose. To make it officially a time series, lets apply the  ts() function to it:




But, we are off track, let's get back to autocorrelation. Let's create various lagged time series data sets and let’s graph them, looking for that linear relationship:

autocorr4  autocorr5autocorr6




And now I confess that there is an  function that does all this, but I wanted demonstrate what the  command is about.


In fact, the acf() command in R will graph the autocorrelation coefficients versus the lag, and this graph is referred to as the auto correlation function or ACF. The data is said to not show auto correlation whenever the auto correlation coefficients are close to zero. The time series that shows no auto correlation is called white noise. But what does it mean for the auto correlation coefficients to be close to zero? Well, it turns out that if  95% of these coefficients are within \pm \frac{2}{\sqrt{T}}  , where T  is the length of the time series, then the time series is a white noise series.
Let's look at the ACF  of  the monthly time series monthlyTS :


Note that the length of the time series, monthlyTS,  is

And the blue horizontal lines on the above graph represent the upper and lower bounds   \pm \frac{2}{\sqrt{T}} = \pm 0.2.


Example of a White Noise Time Series

Let's generate  uniformly distributed random numbers between  and .

Its histogram should show that it is of uniform distribution:



Next, let's plot  first as a scatter plot then as a line plot:




So, the question is, does this data set show auto correlation? To find out, let's graph its lagged scatter plots:




Whew, none of these graph show any evidence of a linear relationship, but just to be certain, here is the ACF graph of  the white_noise:


And, yes!  All the auto correlation coefficient are within the bounds of -0.2 and 0.2, with the exception when  Lag = 1 (the coefficient there is equal to one since the series is in linear relationship with itself.)

Autocorrelation - A Brief Overview Using R

One thought on “Autocorrelation - A Brief Overview Using R

  • April 18, 2017 at 4:58 am

    i have a question how we can calculate the acf and pacf values of our data ?


Leave a Reply

Your email address will not be published. Required fields are marked *