# corrcoef

Correlation coefficients

## 📝 Syntax

* R = corrcoef(M)

## 📥 Input argument

* M - a vector or matrix

## 📤 Output argument

* R - Correlation coefficients of M.

## 📄 Description

R = corrcoef(M) returns the matrix of correlation coefficients for M, where the columns of M represent random variables and the rows represent observations.

The Pearson correlation coefficient between variables $$X$$

and $$Y$$

is: $$r\_{XY} = \frac{\text{cov}(X,Y)}{\sigma\_X \sigma\_Y} = \frac{\sum\_{i=1}^n (x\_i - \bar{x})(y\_i - \bar{y})}{\sqrt{\sum\_{i=1}^n (x\_i - \bar{x})^2 \sum\_{i=1}^n (y\_i - \bar{y})^2}}$$

where $$\bar{x}$$

and $$\bar{y}$$

are the sample means, and $$\sigma\_X$$

, $$\sigma\_Y$$

are the standard deviations.

The correlation coefficient ranges from -1 to +1, where -1 indicates perfect negative correlation, +1 indicates perfect positive correlation, and 0 indicates no linear correlation.

## 💡 Example

```matlab
M = [4 -7 3; 1 4 -2; 10 7 9];
R = corrcoef(M)
```

## 🔗 See also

[cov](https://nelson-9.gitbook.io/Nelson/markdown/en/statistics/cov), [mean](https://nelson-9.gitbook.io/Nelson/markdown/en/statistics/mean).

## 🕔 History

| Version | 📄 Description  |
| ------- | --------------- |
| 1.0.0   | initial version |
