Correlation Coefficient
One number between -1 and 1 that says how closely a cloud of points hugs a straight line, and in which direction. Drag the points and watch it move before you learn the formula.
Last updated
Put two measurements side by side, hours of sleep and reaction time, or temperature and ice cream sales, and plot one against the other. Sometimes the points drift upwards from left to right, sometimes downwards, sometimes they form a shapeless cloud. The correlation coefficient r turns that impression into one number between -1 and 1.
Drag the points below. The two dashed lines mark the mean of x and the mean of y, and every point is coloured by where it sits relative to them. Try the three presets first, then pull a single point far away from the rest and watch what it does to r.
Drag the points. Blue points pull r up, orange points pull it down: each one is coloured by which side of the two dashed means it sits on.
What the number says
r always lies between -1 and 1, and it carries two separate pieces of information.
The sign is the direction. Positive r means that when x is larger, y tends to be larger too. Negative r means that when x is larger, y tends to be smaller. It says nothing about how steep the trend is: a line rising gently and a line rising sharply can both have r = 1.
The size is how tightly the points hug a straight line. At exactly 1 or -1 every point sits on one line. At 0 there is no straight-line trend at all.
The plot above labels r with the cut-offs most textbooks use:
| size of r | label | what the scatter plot looks like |
|---|---|---|
| exactly 1 | perfect | every point on one line |
| 0.7 or more | strong | a clear, narrow band |
| 0.4 up to 0.7 | moderate | a visible trend with plenty of scatter |
| 0.1 up to 0.4 | weak | a tilt you would miss without the number |
| under 0.1 | none | no straight-line trend |
These boundaries are a convention, not a theorem. They are useful for describing a result in words, and every field shifts them: a physicist who measures r = 0.9 between two quantities that should be exactly proportional has a problem, while a psychologist who finds r = 0.4 between two traits has a result.
Where the formula comes from
Each point sits in one of four regions made by the two dashed means. A point up and to the right of the centre has x above its mean and y above its mean. Up and to the left, x is below and y is above. The whole formula is built on that picture:
r = Σ(x - x̄)(y - ȳ) / √(Σ(x - x̄)² Σ(y - ȳ)²)
Look at the top first. For each point, multiply how far x is from its mean by how far y is from its mean. In the top-right and bottom-left regions both distances have the same sign, so the product is positive. In the other two regions the signs differ and the product is negative. Adding the products gives a total whose sign is the sign of r, which is why the colours in the plot tell you the direction before the number does: the blue points push r up and the orange points pull it down.
The bottom only rescales. It divides by the spread of x and the spread of y, so the result no longer depends on units and cannot go past 1 in either direction.
Working it out by hand
Take five points: x = 1, 2, 3, 4, 5 and y = 2, 4, 5, 4, 5. The mean of x is 3 and the mean of y is 4.
| x | y | x - 3 | y - 4 | product | (x - 3)² | (y - 4)² |
|---|---|---|---|---|---|---|
| 1 | 2 | -2 | -2 | 4 | 4 | 4 |
| 2 | 4 | -1 | 0 | 0 | 1 | 0 |
| 3 | 5 | 0 | 1 | 0 | 0 | 1 |
| 4 | 4 | 1 | 0 | 0 | 1 | 0 |
| 5 | 5 | 2 | 1 | 2 | 4 | 1 |
| total | 6 | 10 | 6 |
So r = 6/√60 = √15/5, which is about 0.7746: a strong positive correlation.
Notice that the exact answer is a square root. Here r² works out to exactly 3/5, a plain fraction, and r is its square root with the sign of the top line attached. That is why the correlation coefficient calculator prints r as a radical with its decimal beside it rather than a rounded decimal alone.
Many textbooks give the same formula in a form that needs only running totals, with no means subtracted first:
r = (nΣxy - ΣxΣy) / √((nΣx² - (Σx)²)(nΣy² - (Σy)²))
For the same five points n = 5, Σx = 15, Σy = 20, Σxy = 66, Σx² = 55 and Σy² = 86. The top is 5 × 66 minus 15 × 20 = 30, and the two brackets underneath are 50 and 30, so r = 30 / √1500, the same √15/5.
r and r squared
Square r and you get r², the coefficient of determination. For the five points above, r² = 0.6. It reads as a share: the line of best fit through these points accounts for 60% of the variation in y, and the other 40% is scatter the line cannot explain.
The two numbers answer different questions. r tells you direction and strength together, which is what you want when describing a relationship. r² drops the sign, so r = -0.9 and r = 0.9 both give 0.81, and it is the number to quote when the question is how much a line explains. It is also always smaller than |r| unless r is 0 or ±1, so an r of 0.5 that sounds respectable becomes an r² of 0.25: the line explains a quarter of the variation.
Correlation is not causation
A strong r says two quantities move together in this data. It does not say why, and there are three common reasons that have nothing to do with one causing the other.
- A third quantity drives both. Ice cream sales and swimming accidents rise and fall together. Hot weather causes both.
- The cause runs the other way. Windmills turn faster on days with stronger wind. The wind turns the windmills; the windmills do not make the wind.
- Coincidence. Compare enough unrelated series and some will line up by chance, especially over a handful of years.
Showing that x causes y needs something correlation cannot supply: a controlled experiment, or an argument about the mechanism that rules out the alternatives.
What r cannot see
The number is a summary, and a summary hides things. Three are worth knowing.
Curves. The points (-2, 4), (-1, 1), (0, 0), (1, 1), (2, 4) lie exactly on y = x^2, and their correlation coefficient is exactly 0. The left half falls, the right half rises, and the products cancel. r measures straight-line relationships only, so a perfect curve can score nothing.
Outliers. Start from the five points above, r ≈ 0.7746, and add a single point at (10, 0). The new r is about -0.5529. One point flipped the sign. It works the other way too: x = 1 to 5 with y = 3, 1, 4, 1, 5 has a weak r ≈ 0.3536, and adding one point at (12, 12) lifts it to about 0.9084 without changing the other five at all. Try both in the plot: drag one point to a corner and watch r.
What does not matter. Changing units leaves r alone. Measure x in centimetres instead of metres, or multiply every x by 10, and r is still √15/5. Swapping which variable is x and which is y also leaves r unchanged, unlike the line of best fit, which changes when you swap them.
So look at the scatter plot before quoting r, and check the residuals of the fitted line for a pattern the number would hide.
Try one
The answer is positive even though r is negative, and it is smaller than 0.9. If you got -0.81, the sign was carried into the square; if you got 0.9, the square was skipped. To find r for your own data, paste the two columns into the correlation coefficient calculator, which shows the table of sums and the formula filled in.
Common questions
- What is the correlation coefficient?
- The correlation coefficient r, also called Pearson's r, is a number between -1 and 1 that measures how closely two quantities follow a straight-line relationship. Its sign gives the direction: positive when y tends to rise with x, negative when it tends to fall. Its size gives the strength: near 1 or -1 the points sit close to a line, near 0 there is no linear pattern at all.
- How do you calculate the correlation coefficient?
- Subtract the mean of x from every x and the mean of y from every y. Multiply each pair of differences and add the products. Divide that total by the square root of (the sum of the squared x differences) times (the sum of the squared y differences). For x = 1, 2, 3, 4, 5 and y = 2, 4, 5, 4, 5 the products add to 6, the squares add to 10 and 6, so r = 6 / √60 = √15/5, about 0.7746.
- What is a strong correlation coefficient?
- A common convention, and the one this page's plot uses, calls |r| of 0.7 or more strong, 0.4 up to 0.7 moderate, 0.1 up to 0.4 weak, and anything under 0.1 no linear correlation. These cut-offs are a habit rather than a law. In physics an r of 0.9 can be disappointing; in psychology or economics 0.4 can be a notable finding.
- What is the difference between r and r squared?
- r keeps the direction and r² does not. r² is the share of the variation in y that the straight line accounts for, so r = 0.7746 means r² = 0.6, and the line accounts for 60% of how much y varies. An r of -0.9 and an r of 0.9 both give r² = 0.81: equally tight, opposite directions.
- Can the correlation coefficient be greater than 1?
- No. r always lies between -1 and 1, and it reaches either end only when every point sits exactly on one straight line. If you calculate an r of 1.2, a sum in the table is wrong; the usual culprit is squaring the sum of x instead of summing the squares of x.
- Does correlation mean causation?
- No. A strong r says two quantities move together in the data you have. It cannot say which one drives the other, or whether a third quantity drives both. Ice cream sales and swimming accidents rise together because hot weather raises both; neither causes the other. Establishing a cause takes an experiment or a careful argument about the mechanism, not a correlation.
- Why does r = 0 not mean there is no relationship?
- r only measures straight-line relationships. The points (-2, 4), (-1, 1), (0, 0), (1, 1), (2, 4) lie exactly on y = x², a perfect relationship, and their correlation coefficient is exactly 0, because the falling left half cancels the rising right half. Always look at the scatter plot before trusting the number.
Want to run this on your own numbers?
Correlation Coefficient Calculator Open the calculator