MathsStatistics & Probability

Correlation Coefficient
calculator.

See how closely two sets of paired numbers follow a straight line, with Pearson's r.

How it's worked out

Pearson's r runs from −1, where every point lies on a falling line, through 0, where there is no straight-line trend, to +1, where every point lies on a rising line. It has no units, so it does not matter whether you measure in inches or meters.

It comes from three sums around the means of x and y, written with x‾\bar{x} and y‾\bar{y}.

Sxy\displaystyle S_{xy}=∑(x−x‾)(y−y‾)\displaystyle {}= \sum (x - \bar{x})(y - \bar{y})
Sxx\displaystyle S_{xx}=∑(x−x‾)2\displaystyle {}= \sum (x - \bar{x})^2
Syy\displaystyle S_{yy}=∑(y−y‾)2\displaystyle {}= \sum (y - \bar{y})^2
r\displaystyle r=SxySxxSyy\displaystyle {}= \frac{S_{xy}}{\sqrt{S_{xx} S_{yy}}}

Next comes a t test, which asks how often a sample of this size would show so large an r if there were no link at all. The two-tailed p-value uses n − 2 degrees of freedom.

t\displaystyle t=rn−21−r2\displaystyle {}= r \sqrt{\frac{n - 2}{1 - r^2}}

The interval for r uses Fisher's z transform. It turns r into z, builds a symmetric interval on that scale with a standard error of 1n−3\frac{1}{\sqrt{n-3}}, and turns the limits back into r. That takes at least 4 pairs.

z\displaystyle z=atanh⁡(r)\displaystyle {}= \operatorname{atanh}(r)

Worked examples

Maya tracks study hours and test scores

Maya asks eight classmates for their study hours (1, 2, 3, 4, 5, 6, 7, 8) and scores (52, 55, 61, 64, 70, 71, 78, 83). The data give r = 0.994 and r² = 0.988, with t = 22.68 on 6 degrees of freedom.

The p-value is below 0.001, and the 95% interval for the true correlation runs from 0.967 to 0.999. The fitted line adds about 4.38 points per hour. That does not show that extra hours cause higher scores, since students who study more may differ in other ways.

Open this example in the tool

Ben works five pairs by hand

Ben has x = 1, 2, 3, 4, 5 and y = 2, 4, 5, 4, 5. The means are 3 and 4, which give the three sums.

r\displaystyle r=610×6\displaystyle {}= \frac{6}{\sqrt{10 \times 6}}=0.775\displaystyle {}= 0.775

That looks strong, but p = 0.124. With only 5 pairs, r has to reach ±0.878 to pass the 5% level, and 0.775 falls short. His 95% interval runs from −0.34 to 0.984, which still includes 0.

Open this example in the tool

Anscombe's third data set hides an outlier

Anscombe's four data sets share nearly the same r, at 0.816, 0.816, 0.816, 0.817, yet they look nothing alike when plotted. One rises in a clean line with scatter, one bends, one is a straight line with a single stray point, and one is a vertical stack with one far point.

In the third, r is 0.816. Leave out pair 3, at (13, 12.74), and r rises to 0.999997, because the other ten pairs lie almost exactly on a line. In the fourth, the far point at (19, 12.5) is the only reason r exists at all: leave it out and every remaining x is 8, so no correlation can be worked out.

Open this example in the tool

Reading your result

Look at the plot before the number. r only measures straight-line association. Anscombe's four sets are the classic warning, as the same r can come from very different patterns.

Read size and direction together. The sign gives the direction, and the distance from 0 gives the size. Cohen's bands call 0.10 small, 0.30 medium and 0.50 large. They were set for behavioral research, so a physical measurement may need far more.

Read r² as a share. r² is the share of variation in y that the straight line accounts for. Maya's r² of 0.988 means the line explains about 99% of the spread in her scores.

Significance depends on the number of pairs. The r needed at the 5% level falls from 0.878 at 5 pairs to 0.632 at 10, 0.444 at 20, 0.279 at 50 and 0.197 at 100. So a small r can be significant in a large sample, and a large r may not be in a small one.

Common mistakes

  • Treating r as proof of cause. Strong correlation does not suggest that x causes y. A third factor can drive both, or the cause can run the other way.
  • Reading r = 0 as "no relationship". For x from −2 to 2, y = x² fits perfectly, yet r = 0. There is a clear pattern, just not a straight line.
  • Comparing r across different ranges. Cut Maya's data down to 3 to 6 hours and r falls from 0.994 to 0.969, simply because x varies less.
  • Using it on dependent data. The test assumes independent errors. Time series or repeated measures on one person need other methods.
  • Pairing the columns wrongly. Each x must sit beside its own y. Sorting one column on its own changes r completely.

Questions people ask

It depends on the field. Cohen's bands treat 0.50 as large for behavioral research, while a physical measurement might need 0.95 or more before anyone trusts it. Report r with its interval and let readers judge it against what is normal in that area.

Sources