ccvf <- crosscov(y [,nlags] [,degree:d] [,auto:T] [,cor:T]\ [,full:T or center:T] [,nfreq:M]), REAL matrix y, integer nlags > 0, integer scalar or vector d, integer M > 0 ccvf <- crosscov(y, i, j [,nlags] [,degree:d] [,cor:T] \ [,full:T or center:T] [,nfreq:M]), integers i > 0, j > 0 |

c_yy <- crosscov(y, nlags) computes sample auto- and crosscovariance functions ccvf(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. c_yy will be a nlags+1 by ny by ny REAL array, with c_yy[h+1,i,j] = ccvf(h,y[,i],y[,j]), h = 0, ..., nlags, where 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]. Covariances where y[,j] leads h ahead of y[,i] are in c_yy[h+1,j,i]. crosscov(y) is the same as crosscov(y,nrows(y)-1), computing all non-degenerate sample autocovariances. c_yy <- crosscov(y, i, j [,nlags]) computes ccvf(k,i,j) for k = -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 ccvf(k,i,j) only for k >= 0, use full:F as an argument. c_yy <- crosscov(y [,nlags], auto:T) computes only autocovariances. The result is a matrix with ny columns with c_yy[h+1,j] = ccvf(h, y[,j],y[,j]), h = 0,...,nlags, j = 1,...,ny. crosscov(y, i, j [,nlags], auto:T) is legal only when i = j. c_yy <- crosscov(y [,nlags] full:T) does the same, except auto- and cross-covariances are also computed for negative lags. c_yy will be a 2*nlags+1 by ny by ny array, with results for lags 0 through nlags in c_yy[1,,], c_yy[2,,],..., c_yy[nlags+1,,], and results for lags -1 through -nlags in c_yy[2*nlags+1,,], c_yy[2*nlags,,],..., c_yy[nlags+2,,]. c_yy <- crosscov(y [,nlags] center:T) does the same as with full:T, except the auto- and cross-covariance functions are centered at row nlags+1. Specifically, results for lags -nlags, -nlags+1, ..., -1, 0, 1, ..., nlags are in c_yy[1,,], c_yy[2,,], ..., c_yy[2*nlags+1,,] With auto:T, with either full:T or center:T, c_yy will be a 2*nlags+1 by ny matrix. You can specify that columns of y be detrended by subtracting a polynomial in time using keyword phrase 'degree:d', where d is an integer scalar or vector of length ny = ncols(y). A scalar d is interpreted as rep(d,ny). c_yy <- crosscov(y [,nlags], degree:d) computes auto- and cross- covariances of the residuals from polynomial trends fit by least squares to each column of y. The values of the fitted polynomial replace ybar in the definition of ccvf. d[j] is the degree of the polynomial fit to column j. When d[j] = 0, only the sample mean is subtracted (default). When d[j] < 0, nothing is subtracted. You can use keyword phrases 'full:T', 'center:T' and 'auto:T' with 'degree:d' r_yy <- crosscov(y [,i,j] [,nlags], cor:T ...) computes auto- and cross- correlations instead of auto- and cross-covariances. You can use any of the other keywords with 'cor:T'. Note that, unlike autocor(), the result includes lag 0 correlations. The necessary sums of lagged products are computed using discrete Fourier transforms (DFTs) of length >= N + nlags, the actual length chosen being M = goodfactors(N + nlags). See goodfactors(). When working with long time series, it may be possible to find M1 > M with more small factors resulting in faster DFT computation. For example, when N + nlags = 24388, M = goodfactors(24388) = 24389 = 29^3, but a DFT of length M1 = 24576 = 3*2^13 takes only about 40% as long to compute as a DFT of length M. c_yy <- crosscov(y[,i,j] [,nlags], nfreq:M1 ...) uses DFTs of length M1. See also crosscor(), autocov(), autocor().

Gary Oehlert 2003-01-15