How to calculate r (the correlation coefficient)

The correlation coefficient r measures how closely two variables follow a straight line, from −1 to 1. Here is how to calculate it by hand in four steps, then the one-line shortcut in Excel, Google Sheets and on a TI-84.

By Ahmad Saleem, M.Sc. Mathematics & Statistics · Updated

Skip the manual work Use the free correlation coefficient calculator Pearson or Spearman correlation for paired data, with r², a significance test and every step shown.

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).

  1. Find the means. x = 21 / 6 = 3.5 and y = 396 / 6 = 66.
  2. Subtract the means from every x and every y.
  3. Multiply and square the deviations, then add up each column.
  4. Divide the sum of products by the square root of the two sums of squares multiplied together.
Steps 2 and 3: deviations from the means (mean of x = 3.5, mean of y = 66)
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
  1. The three sums from the table
    Sxy = 89, Sxx = 17.5, Syy = 498
  2. 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:

  1. 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:

D2=CORREL(A2:A7,B2:B7)
ABCD
1HoursScorer
2 1 55 0.9534
3 2 60 r²
4 3 58 0.9089
5 4 70
6 5 72
7 6 81
CORREL returns 0.9534. =RSQ(B2:B7,A2:A7) in D4 gives r² = 0.9089.
  • =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

  1. Press STAT, choose 1:Edit, and type the x values in L1 and the y values in L2.
  2. 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.
  3. Press STAT, move right to CALC, choose 8:LinReg(a+bx) (or 4:LinReg(ax+b)) and press ENTER.
  4. 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.

Frequently asked questions

What does r = 0 mean?

It means there is no straight-line relationship. There can still be a strong curved one: points shaped like a U can have r close to 0. That is why you should always look at a scatter plot before trusting r.

What is the difference between r and r²?

r runs from −1 to 1 and shows the direction and strength of the linear relationship. r² (the coefficient of determination) runs from 0 to 1 and is the share of the variation in y that a straight line on x explains. In the example, r = 0.953 and r² = 0.909, so the line explains about 91% of the variation in scores.

Does it matter which variable is x and which is y?

Not for r: swapping x and y gives exactly the same correlation. It does matter for the regression line, the equation you use to predict y from x, which changes if you swap them.

How do I know if my r is statistically significant?

Convert it to a t statistic, t = r√(n − 2) / √(1 − r²), with n − 2 degrees of freedom. For the example, t = 6.32 with 4 df, so p = 0.003, which is significant at the 5% level. The correlation coefficient calculator does this for you.