acor: autocorrelation

acorR Documentation

autocorrelation

Description

autocorrelation of a sequence

Usage

acor(X, k = 1, na.rm = FALSE)

Arguments

X

a numeric vector or zoo vector

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

Value

Returns the lag k autocorrelation of X, e.g., the correlation of X[i] with X[i-k].

Note

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.

Author(s)

Matthew Clegg matthewcleggphd@gmail.com

See Also

acf

Examples

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

matthewclegg/egcm documentation built on March 5, 2023, 6:33 a.m.