Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

xcov

Cross-covariance


Description

Compute covariance at various lags (= correlation(x-mean(x), y-mean(y))).

Usage

xcov(
  x,
  y = NULL,
  maxlag = if (is.matrix(x)) nrow(x) - 1 else max(length(x), length(y)) - 1,
  scale = c("none", "biased", "unbiased", "coeff")
)

Arguments

x

Input, numeric or complex vector or matrix. Must not be missing.

y

Input, numeric or complex vector data. If x is a matrix (not a vector), y must be omitted. y may be omitted if x is a vector; in this case xcov estimates the autocovariance of x.

maxlag

Integer scalar. Maximum covariance lag. If omitted, the default value is N-1, where N is the greater of the lengths of x and y or, if x is a matrix, the number of rows in x.

scale

Character string. Specifies the type of scaling applied to the covariation vector (or matrix). matched to one of:

"none"

return the unscaled covariance, C

"biased"

return the biased average, C/N

"unbiased"

return the unbiased average, C(k)/(N-|k|)

"coeff"

return C/(covariance at lag 0)

, where k is the lag, and N is the length of x If omitted, the default value is "none". If y is supplied but does not have the same length as x, scale must be "none".

Value

A list containing the following variables:

C

array of covariance estimates

lags

vector of covariance lags [-maxlag:maxlag]

The array of covariance estimates has one of the following forms:

  1. Cross-covariance estimate if X and Y are vectors.

  2. Autocovariance estimate if is a vector and Y is omitted.

  3. If x is a matrix, C is a matrix containing the cross-covariance estimates of each column with every other column. Lag varies with the first index so that C has 2 * maxlag + 1 rows and P^2 columns where P is the number of columns in x.

Author(s)

Paul Kienzle, pkienzle@users.sf.net.
Conversion to R by Geert van Boxtel, G.J.M.vanBoxtel@gmail.com.

See Also

Examples

x <- rnorm(1000)
cl <- xcov(x, maxlag = 10, scale = 'coeff')
plot (cl$lags, cl$C, type = "h", xlab = "", ylab = "")
points (cl$lags, cl$C)
abline(h = 0)

gsignal

Signal Processing

v0.3-1
GPL-3
Authors
Geert van Boxtel [aut, cre] (Maintainer), Tom Short [aut] (Author of 'signal' package), Paul Kienzle [aut] (Majority of the original sources), Ben Abbott [ctb], Juan Aguado [ctb], Muthiah Annamalai [ctb], Leonardo Araujo [ctb], William Asquith [ctb], David Bateman [ctb], David Billinghurst [ctb], Juan Pablo Carbajal [ctb], André Carezia [ctb], Vincent Cautaerts [ctb], Eric Chassande-Mottin [ctb], Luca Citi [ctb], Dave Cogdell [ctb], Carlo de Falco [ctb], Carne Draug [ctb], Pascal Dupuis [ctb], John W. Eaton [ctb], R.G.H Eschauzier [ctb], Andrew Fitting [ctb], Alan J. Greenberger [ctb], Mike Gross [ctb], Daniel Gunyan [ctb], Kai Habel [ctb], Kurt Hornik [ctb], Jake Janovetz [ctb], Alexander Klein [ctb], Peter V. Lanspeary [ctb], Bill Lash [ctb], Friedrich Leissh [ctb], Laurent S. Mazet [ctb], Mike Miller [ctb], Petr Mikulik [ctb], Paolo Neis [ctb], Georgios Ouzounis [ctb], Sylvain Pelissier [ctb], Francesco Potortì [ctb], Charles Praplan [ctb], Lukas F. Reichlin [ctb], Tony Richardson [ctb], Asbjorn Sabo [ctb], Thomas Sailer [ctb], Rolf Schirmacher [ctb], Rolf Schirmacher [ctb], Ivan Selesnick [ctb], Julius O. Smith III [ctb], Peter L. Soendergaard [ctb], Quentin Spencer [ctb], Doug Stewart [ctb], P. Sudeepam [ctb], Stefan van der Walt [ctb], Andreas Weber [ctb], P. Sudeepam [ctb], Andreas Weingessel [ctb]
Initial release
2021-05-02

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.