Post · 3 min read· pp. 241–243

1.3.5.12. Autocorrelation

1. Exploratory Data Analysis 1.3. EDA Techniques 1.3.5. Quantitative Techniques
Purpose: Detect Non-Randomness, Time Series ModelingThe autocorrelation ( Box and Jenkins, 1976) function can be used for the following two purposes: 1. To detect non-randomness in data. 2. To identify an appropriate time series model if the data are not random.
DefinitionGiven measurements, Y1, Y2, ..., YN at time X1, X2, ..., XN, the lag k autocorrelation function is defined as
rk=∑i=1N−k(Yi−Yˉ)(Yi+k−Yˉ)∑i=1N(Yi−Yˉ)2r_{k} = \frac{\sum_{i=1}^{N-k}(Y_{i} - \bar{Y})(Y_{i+k} - \bar{Y})} {\sum_{i=1}^{N}(Y_{i} - \bar{Y})^{2} }
Although the time variable, X, is not used in the formula for autocorrelation, the assumption is that the observations are equi-spaced. Autocorrelation is a correlation coefficient. However, instead of correlation between two different variables, the correlation is between two values of the same variable at times Xi and Xi+k. When the autocorrelation is used to detect non-randomness, it is usually only the first (lag 1) autocorrelation that is of interest. When the autocorrelation is used to identify an appropriate time series model, the autocorrelations are usually plotted for many lags.
Autocorrelation ExampleLag-one autocorrelations were computed for the the LEW.DAT data set. ```text

lag autocorrelation 0. 1.00

  1. code
    -0.31
  2. code
    -0.74
  3. code
     0.77
  4. code
     0.21
  5. code
    -0.90
  6. code
     0.38
  7. code
     0.63
  8. code
    -0.77
  9. code
    -0.12
  10. code
     0.82
  11. code
    -0.40
  12. code
    -0.55
  13. code
     0.73
  14. code
     0.07
  15. code
    -0.76
  16. code
     0.40
  17. code
     0.48
  18. code
    -0.70
  19. code
    -0.03
  20. code
     0.70
  21. code
    -0.41
  22. code
    -0.43
  23. code
     0.67
  24. code
     0.00
  25. code
    -0.66
  26. code
     0.42
  27. code
     0.39
  28. code
    -0.65
  29. code
     0.03
  30. code
     0.63
  31. code
    -0.42
  32. code
    -0.36
  33. code
     0.64
  34. code
    -0.05
  35. code
    -0.60
  36. code
     0.43
  37. code
     0.32
  38. code
    -0.64
  39. code
     0.08
  40. code
     0.58
  41. code
    -0.45
  42. code
    -0.28
  43. code
     0.62
  44. code
    -0.10
  45. code
    -0.55
  46. code
     0.45
  47. code
     0.25
  48. code
    -0.61
  49. code
     0.14
|
| *Questions* | The autocorrelation function can be used to answer the following questions.  1. Was this sample data set generated from a random    process? 2. Would a non-linear or time series model be a more    appropriate model for these data than a simple    constant plus error model? |
| *Importance* | Randomness is one of the key [assumptions](/u/e9b6365236531caf) in determining if a univariate statistical process is in control. If the assumptions of constant location and scale, randomness, and fixed distribution are reasonable, then the univariate process can be modeled as:  
Yi=A0+EiY_{i} = A_0 + E_{i}
where ***E<sub>i</sub>*** is an error term. If the randomness assumption is not valid, then a different model needs to be used. This will typically be either a [time series model](https://www.itl.nist.gov/div898/handbook/pmc/section4/pmc4.htm) or a [non-linear model](https://www.itl.nist.gov/div898/handbook/pmd/section1/pmd142.htm) (with time as the independent variable). | | *Related Techniques* | [Autocorrelation Plot](https://www.itl.nist.gov/div898/handbook/eda/section3/autocopl.htm) [Run Sequence Plot](https://www.itl.nist.gov/div898/handbook/eda/section3/runseqpl.htm) [Lag Plot](https://www.itl.nist.gov/div898/handbook/eda/section3/lagplot.htm) [Runs Test](/u/889b42ffc5a35b39) | | *Case Study* | The [heat flow meter](/u/3efc7eda3fa35f69) data demonstrate the use of autocorrelation in determining if the data are from a random process. | | *Software* | The autocorrelation capability is available in most general purpose statistical software programs. Both [Dataplot code](https://www.itl.nist.gov/div898/handbook/eda/section3/eda35c.dp) and [R code](https://www.itl.nist.gov/div898/handbook/eda/section3/eda35c.r) can be used to generate the analyses in this section. These scripts use the [LEW.DAT](https://www.itl.nist.gov/div898/handbook/datasets/LEW.DAT) data file. |