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 XX

and YY

is: rXY=cov(X,Y)σXσY=i=1n(xixˉ)(yiyˉ)i=1n(xixˉ)2i=1n(yiyˉ)2r_{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 xˉ\bar{x}

and yˉ\bar{y}

are the sample means, and σX\sigma_X

, σY\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

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

🔗 See also

cov, mean.

🕔 History

Version
📄 Description

1.0.0

initial version

Last updated

Was this helpful?