# 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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ai.nuhil.net/statistics/correlation-and-covariance.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
