dcf: Compute the Discrete Correlation Function

Description Usage Arguments Value Notes See Also Examples

View source: R/dcf_functions.R

Description

dcf returns the Discrete Correlation Function estimates.

Usage

1
2
dcf(ts.1, ts.2, tau = NULL, min.pts = 5, local.est = FALSE,
  zero.clip = NULL, use.errors = FALSE, cov = FALSE, chatter = 0)

Arguments

ts.1

(array or dataframe) data for time series 1 and 2.

ts.2

(array or dataframe) data for time series 1 and 2.

tau

(vector) list of lags at which to compute the CCF.

min.pts

(integer) each DCF bin must contain at least min.pts correlation coefficients.

local.est

(logical) use 'local' (not 'global') means and variances?

zero.clip

(logical) remove pairs of points with exactly zero lag?

use.errors

(logical) if TRUE then subtract mean square error from variances.

cov

(logical) if TRUE then compute covariance, not correlation coefficient.

chatter

(integer) set the level of feedback.

Value

A data frame containing columns:

tau

the centre of the lag bins (vector)

ccf

the correlation coefficent in each lag bin

n

the number of data point pairs included in each lag bin

Notes

Input are two time series (data frames with columns: t, y, dy [optional]) Output is the correlation coefficient ccf[i] in different lag bins tau[i].

In what follows we refer to the t, y values of time series 1 (ts.1) as t.1, y.1, and similarly for time series 2.

We first subtract the mean values from y.1 and y.2. Then, within the ith lag bin (tau[i] - dtau/2, tau[i] + dtau/2) we collect all pairs (y.1, y.2) of data for which t.1 - t.2 falls within the lag bin. Using these pairs of data we compute the sum of their product and normalise it:

cov[i] = (1/n) * sum_{j,k=1..n} (y.1[j] * y.2[k])

Here, j, k are index arrays of length n that specify the points of time series 1 and 2 (respectively) which pair-up within lag bin i. This gives a covariance. If cov = TRUE we keep these values. Otherwise (default: cov = FALSE) we normalise by the product of the standard deviations of y.1 and y.2.

The number of output lags tau is 2*lag.bins+1, and the lags are centred on zero. So they run from -max.lag to +max.lag. Any lag bins containing fewer than min.pts pairs of points will have ccf = NA.

If 'errors' are suppled for either or both time series (dx.1, dx.2) and use.errors = TRUE then the variance used in the denominator terms of correlation coefficient calculation will be the 'excess variance', i.e. the total sample variance minus the mean square error. If dy.1 and/or dy.2 are a single number, this is assumed to be the same error for each data point. If use.errors = FALSE (default) then the usual sample variance will be used.

See Also

cross_correlate, iccf

Examples

1
2
3
4
## Example using NGC 5548 data
res <- dcf(cont, hbeta, tau = seq(-200, 200, by = 5))
plot(res$tau, res$ccf, type = "l", col = "blue", lwd = 3, bty = "n")
grid()

svdataman/sour documentation built on April 6, 2018, 11:13 a.m.