# Covariance and Correlation

## Covariance&#x20;

Covariance is a measure of how much two random variables vary together.

* If X and Y are independent then $$Cov(X, Y ) = 0$$ . \
  **Warning**: The converse is false: **zero covariance does not always imply independence**.\


![Zero Covariance doesn't mean Independent variables](https://1877261540-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LFDuA0A2VRqmT31Blrq%2F-LNyJhmFDi76Ur-H5Xqs%2F-LNyJz94Na3vJJhicBPk%2Fimage.png?alt=media\&token=eb3bd57c-c6e5-4acf-b45c-8186d2a0d4ac)

The key point is that $$Cov(X, Y )$$ measures the linear relationship between X and Y . In the above example $$X$$ and $$X^2$$ have a quadratic relationship that is completely missed by $$Cov(X, Y )$$.

* $$Cov(X1 + X2, Y ) = Cov(X1, Y ) + Cov(X2, Y )$$&#x20;

## Correlation

The units of covariance $$Cov(X, Y )$$ are ‘units of $$X$$ times units of $$Y$$ ’. This makes it hard to compare covariances: **if we change scales then the covariance changes as well. Correlation is a way to remove the scale from the covariance**

$$
Cor(X, Y ) = ρ = \frac{Cov(X,Y)}{σ_x σ_y}
$$

* ρ is dimensionless (it’s a ratio!).
* −1 ≤ ρ ≤ 1. Furthermore, \
  ρ = +1 if and only if Y = aX + b with a > 0, \
  ρ = −1 if and only if Y = aX + b with a < 0.

Knowing squared correlation( $$ρ^2$$ ) helps to determine the variance in one variable given the other variable. If is $$ρ^2$$ 0.7 between x and y, it means that x predict 70% variation in y.

{% file src="https://1877261540-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LFDuA0A2VRqmT31Blrq%2F-LNyJhmFDi76Ur-H5Xqs%2F-LNyL_2ubNg5QYA8uUTY%2FMIT18_05S14_Reading7b.pdf?alt=media&token=edcb30ee-4db3-4818-8236-4b4d2daa7b38" %}
Covariance & Coorelation
{% endfile %}

## **Correlation as Dot Product between vectors**

{% file src="https://1877261540-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LFDuA0A2VRqmT31Blrq%2Fuploads%2F28O1OWpwp9LFNkd7Lo45%2F1316032833.pdf?alt=media&token=b2772a35-5fae-4e2a-b543-a00739c7b74b" %}

## **Coorelation Doesn't Mean Causality**

Correlation doesn't equal causation i.e if x and y are highly correlated doesn't means that either of x or y is cause of other.&#x20;

Causation can be only determined by probabilty graphs.&#x20;
