acor | R Documentation |
autocorrelation of a sequence
acor(X, k = 1, na.rm = FALSE)
X |
a numeric vector or |
k |
the number of lags for which to compute the autocorrelation. Default: 1 |
na.rm |
a boolean, which if TRUE, indicates that NA values should be removed from the series prior to computing the autocorrelation. Default: FALSE |
Returns the lag k
autocorrelation of X
, e.g., the correlation
of X[i]
with X[i-k]
.
It's a bit surprising that this is not a part of the core R distribution, but I can't find it. Perhaps it was thought to be too trivial to include.
Matthew Clegg matthewcleggphd@gmail.com
acf
acor(1:10) # a perfect correlation acor(rnorm(100)) # should be close to zero acor(cumsum(rnorm(100))) # slightly less than one acor(rar1(1000, a1=0.8)) # slightly less than 0.8 acor(rar1(1000, a1=0.8), k=2) # about 0.64 acor(rar1(1000, a1=0.8), k=3) # about 0.51
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.