1

Studying autocorrelation using R I ran into a brief exposure by Ryan Sheehy named Autocorrelation in R. In this exposure, the topic and the use of the function acf() are nicely explained and it is illustrated how autocorrelations are in fact lagged correlations. Readers are instructed to run an example that shows that on their data set the result of the acf() function equals the correlation of the variable with its' lagged variable if a correction factor is applied. It works on their example, but in the example I had in mind in the box below, a difference remains.

x<-c(1,4,5,5,7,6,7,7)

## ac according to acf = 0.371
acf(x, plot=FALSE)

## ac from correlations with lagged variable (after correction for (n-1)/n) = 0.692
n<- length(x)
x_t0 <- x[-1]
x_t1 <- x[-n]
cor(x_t1, x_t0) * (n-1)/n 

How?

  • 1
    Hi: The formula for the acf is more complicated than just multiplying by (n-1)/n. If you can get your hands on the text (it's old ) by Ripley and Venables, it might be in there. The book is referred to as MASS which IIRC stands for "Modern Applied Statistics in Splus". – mlofton Mar 09 '20 at 13:44
  • 1
    The discussion at https://stats.stackexchange.com/questions/81754 may have some bearing on this. – whuber Mar 09 '20 at 14:30

0 Answers0