Computing an autocorrelation
In many cases, events occur in a repeating cycle. If the data correlates with itself, this is called an autocorrelation. With some data, the interval may be obvious because there's some visible external influence, such as seasons or tides. With some data, the interval may be difficult to discern.
If we suspect we have cyclic data, we can leverage the
correlation() function from the Computing the coefficient of correlation recipe, earlier in this chapter, to compute an autocorrelation.
The core concept behind autocorrelation is the idea of a correlation through a shift in time, T. The measurement for this is sometimes expressed as : the correlation between x and x with a time shift of T.
Assume we have a handy correlation function, . It compares two sequences of length n, and , and returns the coefficient of correlation between the two sequences:
We can apply this to autocorrelation by using it as a...