> For the complete documentation index, see [llms.txt](https://ai.nuhil.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ai.nuhil.net/statistics/correlation-and-covariance.md).

# Correlation and Covariance

### Correlation

* **Positive** correlation exists when larger values of $$x$$ correspond to larger values of $$y$$ and vice versa.
* **Negative** correlation exists when larger values of $$x$$ correspond to smaller values of $$y$$ and vice versa.
* **Weak or no** correlation exists if there is no such apparent relationship.

![](/files/-LzJ1aO1MvuWkMQuh6XJ)

### Covariance

{% hint style="success" %}
It is a measure that quantifies the strength and direction of a relationship between a pair of variables.
{% endhint %}

$$
cov(x,y)=\frac{1}{n}\sum\_i^n(x\_i-\overline{x})(y\_i-\overline{y})
$$

### Correlation Coefficient

{% hint style="success" %}
The correlation coefficient, or **Pearson** product-moment correlation coefficient is another measure of the correlation between data. You can think of it as a **standardized covariance**.
{% endhint %}

$$
r\_{xy}=\frac{cov(x,y)}{\sigma(x)\sigma(y)}=\frac{\sum\_i^n(x\_i-\overline{x})(y\_i-\overline{y})}{\sqrt{\sum\_i^n(x\_i-\overline{x})^2\sum\_i^n(y\_i-\overline{y})^2}}
$$

> Make a Scatter Plot, and look at it! You may see a correlation that the calculation does not.
>
> **Correlation Is Not Causation** which says that a correlation does not mean that one thing causes the other.
