The formula for r
r = Σ(x − x)(y − y)Σ(x − x)2 · Σ(y − y)2
In words: multiply how far each x and y are from their means, add those products up, and divide by a number that scales the answer to between −1 and 1. Writing the three sums as Sxy, Sxx and Syy:
r = SxySxx Syy
Step by step by hand
Six students recorded the hours they studied (x) and their test score (y): (1, 55), (2, 60), (3, 58), (4, 70), (5, 72) and (6, 81).
- Find the means. x = 21 / 6 = 3.5 and y = 396 / 6 = 66.
- Subtract the means from every x and every y.
- Multiply and square the deviations, then add up each column.
- Divide the sum of products by the square root of the two sums of squares multiplied together.
| x | y | x − 3.5 | y − 66 | Product | (x − 3.5)² | (y − 66)² |
|---|---|---|---|---|---|---|
| 1 | 55 | −2.5 | −11 | 27.5 | 6.25 | 121 |
| 2 | 60 | −1.5 | −6 | 9 | 2.25 | 36 |
| 3 | 58 | −0.5 | −8 | 4 | 0.25 | 64 |
| 4 | 70 | 0.5 | 4 | 2 | 0.25 | 16 |
| 5 | 72 | 1.5 | 6 | 9 | 2.25 | 36 |
| 6 | 81 | 2.5 | 15 | 37.5 | 6.25 | 225 |
| Sum | 0 | 0 | 89 | 17.5 | 498 |
-
The three sums from the table
Sxy = 89, Sxx = 17.5, Syy = 498
-
Divide
r = 8917.5 × 498 = 898715 = 8993.354 = 0.9534
r = 0.953 is a very strong positive correlation: students who studied longer scored higher, and the points lie close to a straight line. A handy check: the deviation columns always add up to 0. If yours don't, there's an arithmetic slip in the means.
The shortcut formula from your textbook
Many textbooks use a version that works from the raw sums, so you don't need the means first. It gives exactly the same answer:
r = nΣxy − ΣxΣy[nΣx2 − (Σx)2][nΣy2 − (Σy)2]
For the example, n = 6, Σx = 21, Σy = 396, Σxy = 1,475, Σx² = 91 and Σy² = 26,634:
-
Plug in the sums
r = 6(1475) − 21(396)[6(91) − 21²][6(26634) − 396²] = 534105 × 2988 = 534560.12 = 0.9534
This version is quicker with a basic calculator but easier to get wrong, because it subtracts large numbers. Keep every digit until the last step.
In Excel or Google Sheets
Put x in column A and y in column B, then type =CORREL(A2:A7,B2:B7) in any empty cell:
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Hours | Score | r | |
| 2 | 1 | 55 | 0.9534 | |
| 3 | 2 | 60 | r² | |
| 4 | 3 | 58 | 0.9089 | |
| 5 | 4 | 70 | ||
| 6 | 5 | 72 | ||
| 7 | 6 | 81 |
- =PEARSON(A2:A7,B2:B7) gives the same result as CORREL.
- =RSQ(B2:B7,A2:A7) gives r² directly.
- The order of the two ranges doesn't matter for CORREL, but both must have the same number of cells, with each pair on the same row.
- The same formulas work in Google Sheets.
On a TI-84 calculator
- Press STAT, choose 1:Edit, and type the x values in L1 and the y values in L2.
- Turn on diagnostics once, or r won't be shown. On a TI-84 Plus CE, press MODE and set STAT DIAGNOSTICS to ON. On older models, press 2nd 0 (CATALOG), scroll to DiagnosticOn and press ENTER twice.
- Press STAT, move right to CALC, choose 8:LinReg(a+bx) (or 4:LinReg(ax+b)) and press ENTER.
- Read r at the bottom of the screen; r² is just above it.
What your r means
- The sign is the direction: positive means y tends to rise with x; negative means it tends to fall.
- The size is the strength. A common rough guide: below 0.2 very weak, 0.2–0.4 weak, 0.4–0.6 moderate, 0.6–0.8 strong, above 0.8 very strong (ignoring the sign).
- r = ±1 means every point is exactly on a line; r = 0 means no straight-line pattern.
Common mistakes
- Mixing up the pairs. Each x must stay with its own y. Sorting one column on its own changes r completely.
- Not looking at the plot. One outlier can create or hide a strong correlation, and a curve can give r near 0. Draw a scatter plot first.
- Reading cause into it. A strong r shows that two things move together, not that one causes the other.
- Using Pearson's r on ranks or ratings with outliers. Spearman's rank correlation is the better choice there; the correlation coefficient calculator does both.
- Rounding too early. Keep full precision in the sums; round only the final r.
To predict one variable from the other, go a step further with the linear regression calculator, which gives the equation of the line through these points.