Covariance

Covariance is a measure used to determine the extent to which two variables change in tandem. It’s a critical statistic for understanding the relationship between two variables. The covariance ( Cov⁡(X,Y )) between two variables X and Y is given by:

Cov⁡(X,Y ) = E[(X − μX)(Y − μY )]

where μX and μY are the means of X and Y , respectively. A positive covariance indicates that the variables tend to move in the same direction, while a negative covariance indicates that they move in opposite directions.

If the (real) random variable pair (X,Y ) can take on the values (xi,yi) for i = 1,…,n, with equal probabilities pi = 1 n, then the covariance can be equivalently written in terms of the means E⁡[X] and E⁡[Y ] as

Cov⁡(X,Y ) = 1 n∑ i=1n(x i − E[X])(yi − E[Y ])