[R] Autocovariance and acf
Christian Lederer
christianlederer at t-online.de
Sat Apr 12 05:17:51 CEST 2003
Hi,
i calculated the autocovariance of a vector x of length n, using
result <- acf(x, lag, type="covariance")
and expected, that result$acf would contain the values
cov(x,x), cov(x[1:(n-1)], x[2:n]) ...
However, acf does not calculate this covariances. Instead
of cov(x[1:(n-i)], x[(i+1):n]) i am getting
( (x[1] - m) * (x[i+1]-m) + ... + (x[n-i]-m) * (x[n]-m) ) / n
where m = mean(x).
I anderstand, that for efficiency reasons only the mean of the whole
vector x is substracted instead of the means of the partial vectors.
But why does it divide by n instead of n-i?
Christian
More information about the R-help
mailing list