The covariance between two variables \(X\) and \(Y\) is defined as
\[
\operatorname{Cov}(X,Y)=\frac{1}{n}\sum_{i=1}^{n}(x_i-\bar{x})(y_i-\bar{y}).
\]
It tells us the direction of the linear relationship: positive when the variables tend to move together, negative when one tends to rise as the other falls. However, covariance has a serious drawback as a measure of strength of association: its value depends on the units in which \(X\) and \(Y\) are measured.
For example, if we measure heights in centimetres instead of metres, every \(x_i\) is multiplied by \(100\), so the covariance is multiplied by \(100\). If we also change the units of \(Y\), the covariance changes again. Thus the same data can give covariances such as \(0.5\), \(50\), or \(5000\) merely by changing units, so the numerical size of the covariance cannot by itself indicate whether the association is strong or weak.
The correlation coefficient \(r\) removes this unit dependence by dividing the covariance by the product of the standard deviations:
\[
r=\frac{\operatorname{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}\,\sqrt{\sum_{i=1}^{n}(y_i-\bar{y})^2}}.
\]
Because the numerator and denominator carry the same units, they cancel, and \(r\) is a pure number. Consequently:
- \(r\) is unaffected by any change of scale or origin (for example, changing metres to centimetres, or shifting all values by a constant).
- \(r\) always lies between \(-1\) and \(1\), so its magnitude has a fixed meaning: values near \(\pm 1\) indicate a strong linear association, and values near \(0\) indicate a weak linear association.
- The sign of \(r\) is the same as the sign of the covariance, so it still gives the direction of the relationship.
Therefore \(r\) is preferred to covariance: it is a unit-free, standardised measure whose value can be compared across different data sets and different units of measurement, whereas covariance gives only the direction and depends on the arbitrary choice of units.