Definitions
Nearby Words

# Covariance

[koh-vair-ee-uhns]

In probability theory and statistics, covariance is a measure of how much two variables change together (the variance is a special case of the covariance when the two variables are identical).

If two variables tend to vary together (that is, when one of them is above its expected value, then the other variable tends to be above its expected value too), then the covariance between the two variables will be positive. On the other hand, when one of them is above its expected value the other variable tends to be below its expected value, then the covariance between the two variables will be negative.

## Definition

The covariance between two real-valued random variables X and Y, with expected values $scriptstyle E\left(X\right),=,mu$ and $scriptstyle E\left(Y\right),=,nu$ is defined as

$operatorname\left\{Cov\right\}\left(X, Y\right) = operatorname\left\{E\right\}\left(\left(X - mu\right) \left(Y - nu\right)\right), ,$

where E is the expected value operator. This can also be written:

$operatorname\left\{Cov\right\}\left(X, Y\right) = operatorname\left\{E\right\}\left(X cdot Y - mu Y - nu X + mu nu\right), ,$
$operatorname\left\{Cov\right\}\left(X, Y\right) = operatorname\left\{E\right\}\left(X cdot Y\right) - mu operatorname\left\{E\right\}\left(Y\right) - nu operatorname\left\{E\right\}\left(X\right) + mu nu, ,$
$operatorname\left\{Cov\right\}\left(X, Y\right) = operatorname\left\{E\right\}\left(X cdot Y\right) - mu nu. ,$

Random variables whose covariance is zero are called uncorrelated.

If X and Y are independent, then their covariance is zero. This follows because under independence,

$E\left(X cdot Y\right)=E\left(X\right) cdot E\left(Y\right)=munu.$

Recalling the final form of the covariance derivation given above, and substituting, we get

$operatorname\left\{Cov\right\}\left(X, Y\right) = mu nu - mu nu = 0.$

The converse, however, is generally not true: Some pairs of random variables have covariance zero although they are not independent. Under some additional assumptions, covariance zero sometimes does entail independence, as for example in the case of multivariate normal distributions.

The units of measurement of the covariance Cov(X, Y) are those of X times those of Y. By contrast, correlation, which depends on the covariance, is a dimensionless measure of linear dependence.

## Properties

If X, Y are real-valued random variables and a, b, c, d are constant ("constant" in this context means non-random), then the following facts are a consequence of the definition of covariance:

$operatorname\left\{Cov\right\}\left(X, a\right) = 0 ,$
$operatorname\left\{Cov\right\}\left(X, X\right) = operatorname\left\{Var\right\}\left(X\right),$
$operatorname\left\{Cov\right\}\left(X, Y\right) = operatorname\left\{Cov\right\}\left(Y, X\right),$
$operatorname\left\{Cov\right\}\left(aX, bY\right) = ab, operatorname\left\{Cov\right\}\left(X, Y\right),$
$operatorname\left\{Cov\right\}\left(X+a, Y+b\right) = operatorname\left\{Cov\right\}\left(X, Y\right),$
$operatorname\left\{Cov\right\}\left(aX+bY, cW+dV\right) = ac,operatorname\left\{Cov\right\}\left(X,W\right)+ad,operatorname\left\{Cov\right\}\left(X,V\right)+bc,operatorname\left\{Cov\right\}\left(Y,W\right)+bd,operatorname\left\{Cov\right\}\left(Y,V\right),$

For sequences X1, ..., Xn and Y1, ..., Ym of random variables, we have

$operatorname\left\{Cov\right\}left\left(sum_\left\{i=1\right\}^n \left\{X_i\right\}, sum_\left\{j=1\right\}^m\left\{Y_j\right\}right\right) = sum_\left\{i=1\right\}^n\left\{sum_\left\{j=1\right\}^m\left\{operatorname\left\{Cov\right\}left\left(X_i, Y_jright\right)\right\}\right\}.,$

For a sequence X1, ..., Xn of random variables, we have

### Incremental computation

Covariance can be computed efficiently from incrementally available values using a generalization of the computational formula for the variance:

$operatorname\left\{Cov\right\}\left(X_i, X_j\right) = operatorname\left\{E\right\}left\left(\left(X_i-operatorname\left\{E\right\}\left(X_i\right)\right)\left(X_j-operatorname\left\{E\right\}\left(X_j\right)\right)right\right) = operatorname\left\{E\right\}\left(X_iX_j\right) -operatorname\left\{E\right\}\left(X_i\right)operatorname\left\{E\right\}\left(X_j\right)$

### Relationship to inner products

Many of the properties of covariance can be extracted elegantly by observing that it satisfies similar properties to those of an inner product:
(1) bilinear: for constants a and b and random variables X, Y, and U, Cov(aX + bY, U) = a Cov(X, U) + bCov(Y, U)
(2) symmetric: Cov(X, Y) = Cov(Y, X)
(3) positive semi-definite: Var(X) = Cov(X, X) ≥ 0, and Cov(X, X) = 0 implies that X is a constant random variable (K).

It can be shown that the covariance is an inner product over some subspace of the vector space of random variables with finite second moment.

## Covariance matrix, operator, bilinear form, and function

For column-vector valued random variables X and Y with respective expected values μ and ν, and respective scalar components m and n, the covariance is defined to be the m×n matrix called the covariance matrix:

$operatorname\left\{Cov\right\}\left(X, Y\right) = operatorname\left\{E\right\}\left(\left(X-mu\right)\left(Y-nu\right)^top\right).,$

For vector-valued random variables, Cov(XY) and Cov(YX) are each other's transposes.

More generally, for a probability measure P on a Hilbert space H with inner product $langle cdot,cdotrangle$, the covariance of P is the bilinear form Cov: H × H → H given by

$mathrm\left\{Cov\right\}\left(x, y\right) = int_\left\{H\right\} langle x, z rangle langle y, z rangle , mathrm\left\{d\right\} mathbf\left\{P\right\} \left(z\right)$

for all x and y in H. The covariance operator C is then defined by

$mathrm\left\{Cov\right\}\left(x, y\right) = langle Cx, y rangle$

(from the Riesz representation theorem, such operator exists if Cov is bounded). Since Cov is symmetric in its arguments, the covariance operator is self-adjoint (the infinite-dimensional analogy of the transposition symmetry in the finite-dimensional case). When P is a centred Gaussian measure, C is also a nuclear operator. In particular, it is a compact operator of trace class, that is, it has finite trace.

Even more generally, for a probability measure P on a Banach space B, the covariance of P is the bilinear form on the algebraic dual $B^#$, defined by

$mathrm\left\{Cov\right\}\left(x, y\right) = int_\left\{B\right\} langle x, z rangle langle y, z rangle , mathrm\left\{d\right\} mathbf\left\{P\right\} \left(z\right)$

where $langle x, z rangle$ is now the value of the linear functional x on the element z.

Quite similarly, the covariance function of a function-valued random element (in special cases called random process or random field) z is

$mathrm\left\{Cov\right\}\left(x, y\right) = int z\left(x\right) z\left(y\right) , mathrm\left\{d\right\} mathbf\left\{P\right\} \left(z\right) = E\left(z\left(x\right) z\left(y\right)\right),$

where $z\left(x\right)$ is now the value of the function z at the point x, i.e., the value of the linear functional $u mapsto u\left(x\right)$ evaluated at z.