Next: crosscov() Up: Time Series Macros Help Previous: costaper()   Contents

crosscor()

Usage:
ccf <- crosscor(x [,nlags] [,degree:d] [,auto:T] [,full:T or center:T]\
  [,nfreq:M]), REAL matrix x, integer nlags > 0, integer scalar or vector
  d, integer M > 0
ccf <- crosscor(x, i, j [,nlags] [,degree:d] [,full:T  or  center:T]\
  [,nfreq:M]), integers i > 0, j > 0



Keywords: autocorrelation, autocovariance, time domain
r_yy <- crosscov(y, nlags) computes sample auto- and crosscorrelation
functions ccf(h,y[,i],y[,j]) for lags h = 0, 1, ..., nlags.

The columns of y, a N by ny REAL matrix with no MISSING elements, are
interpreted as time series defined at equally spaced time points.

r_yy will be a nlags+1 by ny by ny REAL array, with r_yy[h+1,i,j] =
ccf(h,y[,i],y[,j]), h = 0, ..., nlags, where
  ccf(h,y[,i],y[,j]) =
    ccvf(h,y[,i],y[,j])/sqrt(ccvf(h,y[,i],y[,i])*ccvf(h,y[,j],y[,j])),
with
   ccvf(h,y[,i],y[,j]) =
       sum((y[l+h,i]-ybar[i])*(y[l,j]-ybar[j]),l=1,...,N-h)/N.
Note the divisor is N, not N-h or N-h-1.  ybar[j] = sum(y[,j])/N is the
sample mean of y[,j].

Note that y[,j] lags h behind y[,i].  Correlations where y[,j] leads h
ahead of y[,i] are in r_yy[h+1,j,i].

r_yy <- crosscor(y) does the same, except nlags = N-1.

In contrast to the output of autocor(), r_yy contains lag 0 correlations.

r_yy <- crosscor(y, i, j [,nlags]) computes ccf(h,i,j) for h =
-nlags,...,0,...,nlags as a vector of length 2*nlags+1.  Without
center:T (see below), results for lags 0, ..., nlags are in rows 1
through nlags+1 and those for lags -1, ..., -nlags are in rows
2*nlags+1, 2*nlags, ..., nlags+2.  If you want ccf(h,i,j) only for h >=
0, use full:F as an argument.

You can also use crosscov() keyword phrases 'degree:d' (to control
detrending), 'auto:T' (to restrict computations to autocorrelations),
'full:T' (to compute results for negative lags), 'center:T' (to center
lag 0 between negative and positive lags) and 'nfreq:M' (to specify the
length of Fourier transforms used).  See crosscov() for details.

crosscor() is implemented as a macro which uses crosscov() with keyword
phrase 'cor:T' to compute auto- and cross-correlations using discrete
Fourier transforms.  See subtopic 'crosscov:"computation" for details
and for description of the use of keyword 'nfreq'.

See also crosscov(), autocor(), autocov().


Gary Oehlert 2003-01-15