# Correlation Analysis of Signals

The package provides functions to perform correlation analysis of sequential signals.

## Autocovariance and Autocorrelation

StatsBase.autocovFunction
autocov(x, [lags]; demean=true)

Compute the autocovariance of a vector or matrix x, optionally specifying the lags at which to compute the autocovariance. demean denotes whether the mean of x should be subtracted from x before computing the autocovariance.

If x is a vector, return a vector of the same length as x. If x is a matrix, return a matrix of size (length(lags), size(x,2)), where each column in the result corresponds to a column in x.

When left unspecified, the lags used are the integers from 0 to min(size(x,1)-1, 10*log10(size(x,1))).

The output is not normalized. See autocor for a function with normalization.

StatsBase.autocov!Function
autocov!(r, x, lags; demean=true)

Compute the autocovariance of a vector or matrix x at lags and store the result in r. demean denotes whether the mean of x should be subtracted from x before computing the autocovariance.

If x is a vector, r must be a vector of the same length as x. If x is a matrix, r must be a matrix of size (length(lags), size(x,2)), and where each column in the result will correspond to a column in x.

The output is not normalized. See autocor! for a method with normalization.

StatsBase.autocorFunction
autocor(x, [lags]; demean=true)

Compute the autocorrelation function (ACF) of a vector or matrix x, optionally specifying the lags. demean denotes whether the mean of x should be subtracted from x before computing the ACF.

If x is a vector, return a vector of the same length as x. If x is a matrix, return a matrix of size (length(lags), size(x,2)), where each column in the result corresponds to a column in x.

When left unspecified, the lags used are the integers from 0 to min(size(x,1)-1, 10*log10(size(x,1))).

The output is normalized by the variance of x, i.e. so that the lag 0 autocorrelation is 1. See autocov for the unnormalized form.

StatsBase.autocor!Function
autocor!(r, x, lags; demean=true)

Compute the autocorrelation function (ACF) of a vector or matrix x at lags and store the result in r. demean denotes whether the mean of x should be subtracted from x before computing the ACF.

If x is a vector, r must be a vector of the same length as x. If x is a matrix, r must be a matrix of size (length(lags), size(x,2)), and where each column in the result will correspond to a column in x.

The output is normalized by the variance of x, i.e. so that the lag 0 autocorrelation is 1. See autocov! for the unnormalized form.

## Cross-covariance and Cross-correlation

StatsBase.crosscovFunction
crosscov(x, y, [lags]; demean=true)

Compute the cross covariance function (CCF) between real-valued vectors or matrices x and y, optionally specifying the lags. demean specifies whether the respective means of x and y should be subtracted from them before computing their CCF.

If both x and y are vectors, return a vector of the same length as lags. Otherwise, compute cross covariances between each pairs of columns in x and y.

When left unspecified, the lags used are the integers from -min(size(x,1)-1, 10*log10(size(x,1))) to min(size(x,1), 10*log10(size(x,1))).

The output is not normalized. See crosscor for a function with normalization.

StatsBase.crosscov!Function
crosscov!(r, x, y, lags; demean=true)

Compute the cross covariance function (CCF) between real-valued vectors or matrices x and y at lags and store the result in r. demean specifies whether the respective means of x and y should be subtracted from them before computing their CCF.

If both x and y are vectors, r must be a vector of the same length as lags. If either x is a matrix and y is a vector, r must be a matrix of size (length(lags), size(x, 2)); if x is a vector and y is a matrix, r must be a matrix of size (length(lags), size(y, 2)). If both x and y are matrices, r must be a three-dimensional array of size (length(lags), size(x, 2), size(y, 2)).

The output is not normalized. See crosscor! for a function with normalization.

StatsBase.crosscorFunction
crosscor(x, y, [lags]; demean=true)

Compute the cross correlation between real-valued vectors or matrices x and y, optionally specifying the lags. demean specifies whether the respective means of x and y should be subtracted from them before computing their cross correlation.

If both x and y are vectors, return a vector of the same length as lags. Otherwise, compute cross covariances between each pairs of columns in x and y.

When left unspecified, the lags used are the integers from -min(size(x,1)-1, 10*log10(size(x,1))) to min(size(x,1), 10*log10(size(x,1))).

The output is normalized by sqrt(var(x)*var(y)). See crosscov for the unnormalized form.

StatsBase.crosscor!Function
crosscor!(r, x, y, lags; demean=true)

Compute the cross correlation between real-valued vectors or matrices x and y at lags and store the result in r. demean specifies whether the respective means of x and y should be subtracted from them before computing their cross correlation.

If both x and y are vectors, r must be a vector of the same length as lags. If either x is a matrix and y is a vector, r must be a matrix of size (length(lags), size(x, 2)); if x is a vector and y is a matrix, r must be a matrix of size (length(lags), size(y, 2)). If both x and y are matrices, r must be a three-dimensional array of size (length(lags), size(x, 2), size(y, 2)).

The output is normalized by sqrt(var(x)*var(y)). See crosscov! for the unnormalized form.

## Partial Autocorrelation Function

StatsBase.pacfFunction
pacf(X, lags; method=:regression)

Compute the partial autocorrelation function (PACF) of a real-valued vector or matrix X at lags. method designates the estimation method. Recognized values are :regression, which computes the partial autocorrelations via successive regression models, and :yulewalker, which computes the partial autocorrelations using the Yule-Walker equations.

If x is a vector, return a vector of the same length as lags. If x is a matrix, return a matrix of size (length(lags), size(x, 2)), where each column in the result corresponds to a column in x.

StatsBase.pacf!Function
pacf!(r, X, lags; method=:regression)

Compute the partial autocorrelation function (PACF) of a matrix X at lags and store the result in r. method designates the estimation method. Recognized values are :regression, which computes the partial autocorrelations via successive regression models, and :yulewalker, which computes the partial autocorrelations using the Yule-Walker equations.

r must be a matrix of size (length(lags), size(x, 2)).