How to Calculate the Correlation Coefficient

Calculates the correlation coefficient as the covariance ÷ (standard deviation of x × standard deviation of y). It lies between −1 and 1: near 1 means a strong positive relationship, near −1 a strong negative one.

The correlation coefficient expresses the strength of a straight-line relationship between two variables as a number between 1-1 and 11. It is the covariance with the units divided out.

r=sxyσxσyr = \dfrac{s_{xy}}{\sigma_x \, \sigma_y}

As a rough reading guide:

Example

With xx = 1, 2, 3, 4, 5 and yy = 2, 4, 5, 4, 5, the covariance is 1.2 and the standard deviations are

σx=4+1+0+1+45=2=1.4142σy=4+0+1+0+15=1.2=1.0954\sigma_x = \sqrt{\dfrac{4+1+0+1+4}{5}} = \sqrt{2} = 1.4142 \qquad \sigma_y = \sqrt{\dfrac{4+0+1+0+1}{5}} = \sqrt{1.2} = 1.0954
r=1.21.4142×1.0954=1.21.5492=0.7746r = \dfrac{1.2}{1.4142 \times 1.0954} = \dfrac{1.2}{1.5492} = 0.7746

That is a fairly strong positive correlation.

Watch out

Correlation is not causation. Ice cream sales and drownings both rise in summer and are strongly correlated, but ice cream does not drown anyone. A common cause — the temperature — sits behind both.

The coefficient also only detects straight-line relationships. Data following y=x2y = x^2 over a range of xx from 3-3 to 33 has an almost perfect relationship yet a correlation near zero. Always look at the scatter plot.