# Covariance

Covariance[v1,v2]

gives the covariance between the vectors v1 and v2.

Covariance[m]

gives the sample covariance matrix for observations in matrix m.

Covariance[m1,m2]

gives the covariance matrix for the matrices m1 and m2.

Covariance[dist]

gives the covariance matrix for the multivariate symbolic distribution dist.

Covariance[dist,i,j]

gives the (i,j) covariance for the multivariate symbolic distribution dist.

# Details • Covariance[v1,v2] gives the unbiased estimate of the covariance between v1 and v2.
• The lists v1 and v2 must be the same length.
• Covariance[v1,v2] is equivalent to (v1-Mean[v1]). Conjugate[v2-Mean[v2]]/(Length[v1]-1).
• For a matrix m with columns, Covariance[m] is a × matrix of the covariances between columns of m.
• For an × matrix m1 and an × matrix m2, Covariance[m1,m2] is a × matrix of the covariances between columns of m1 and columns of m2.
• Covariance works with SparseArray objects.
• Covariance[dist,i,j] gives Expectation[(xi-μi)(xj-μj),{x1,x2,}dist], where μi is the i component of the mean of dist.
• Covariance[dist] gives a covariance matrix with the (i,j) entry given by Covariance[dist,i,j].

# Examples

open allclose all

## Basic Examples(3)

Covariance between two vectors:

Covariance matrix for a matrix:

Covariance matrix for two matrices:

## Scope(12)

### Data(7)

Exact input yields exact output:

Approximate input yields approximate output:

Covariance between vectors of complexes:

Works with large arrays:

SparseArray data can be used:

Find the covariance of WeightedData:

Find the covariance for data involving quantities:

### Distributions and Processes(5)

Covariance for a continuous multivariate distribution:

Covariance for a discrete multivariate distribution:

Covariance for derived distributions:

Data distribution:

Covariance matrix for a random process at times s and t:

Covariance matrix for TemporalData at times and :

Compare to the covariance of the process slice:

## Applications(3)

Compute the covariance of two financial time series:

Covariance can be used to measure linear association:

Covariance can only detect monotonic relationships:

HoeffdingD can be used to detect a variety of dependence structures:

## Properties & Relations(9)

The covariance matrix is symmetric and positive semidefinite:

A covariance matrix scaled by standard deviations is a correlation matrix:

Covariance and AbsoluteCorrelation are the same for a distribution with zero mean:

SpearmanRho is related to Covariance applied to ranks:

CovarianceFunction for a process is the off-diagonal entry in the covariance matrix:

Covariance and Correlation are the same for standardized vectors:

The covariance of a list with itself is the variance:

The diagonal of a covariance matrix is the variance:

The covariance tends to be large only on the diagonal of a random matrix:

## Neat Examples(1)

Compute the covariance for a GCD array: