Learn R Programming

egcm (version 1.0.13)

acor: autocorrelation

Description

autocorrelation of a sequence

Usage

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

Value

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

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

Author

Matthew Clegg matthewcleggphd@gmail.com

See Also

Examples

Run this code
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

Run the code above in your browser using DataLab