Calculators
Home › Learn › How to Calculate Correlation

How to Calculate Correlation

One table, three sums, one number: the hand method, worked fully.

Published 28 November 2026

Quick answer: Pearson r is Sxy divided by the square root of Sxx times Syy. Seven days of temperature and ice cream sales give Sxy 620, Sxx 112, Syy 3550, so r = 0.9833. A correlation that strong means the two rise together almost in lockstep, and Excel checks it with =CORREL.

A stall, a heatwave, and one number

A woman sells ice cream from a stall by the sea. Seven days in a row she writes down two numbers: the afternoon temperature and the tubs she sold. Monday, 20 degrees, 110 tubs. Tuesday, 22 degrees, 130. By Sunday the pattern feels obvious: hot days sell more. She wants more than a feeling. She wants one number that says how tightly the two move together, and whether the link is strong enough to plan stock around. That number is the correlation coefficient, and she can work it out by hand in one table.

Correlation answers a narrow question. It asks whether two variables rise and fall together along a straight line, and how closely. It does not ask why. The heat may drive the sales, or a sunny weekend may drive both, or the link may be luck. The number comes first. The explanation comes after, and it needs more than the number.

The formula, in three sums

Pearson's correlation coefficient, written r, is built from three sums. Call the two variables x and y. For each pair, take how far x sits from its mean and how far y sits from its mean. Multiply the two distances. Add those products over all the pairs: that sum is Sxy. Then add the squared x distances: Sxx. Add the squared y distances: Syy. The coefficient is the first sum divided by the square root of the other two multiplied together.

Pearson correlationr = Sxy ÷ √(Sxx × Syy)

Each sum has a job. Sxy carries the direction: when x and y sit on the same side of their means, the product is positive, and when they sit on opposite sides it is negative. Sxx and Syy carry the scale: they measure how much each variable spreads on its own. Dividing by them strips the units away, which is why r is the same whether temperature is in Celsius or Fahrenheit and sales are counted in tubs or pounds. The result always lands between −1 and 1. The same three sums build the regression slope too: b = Sxy ÷ Sxx.

The table method, worked by hand

Back to the stall. The seven temperatures are 20, 22, 24, 26, 28, 30 and 32 degrees. Their mean is 26. The seven sales figures are 110, 130, 145, 150, 165, 170 and 180 tubs. Their mean is 150. The table has one row per day, with five columns: the two deviations from the means, their product, and the two squared deviations.

Monday, 20 degrees and 110 tubs: deviations −6 and −40, product 240, squares 36 and 1600. Tuesday, 22 and 130: −4 and −20, product 80, squares 16 and 400. Wednesday, 24 and 145: −2 and −5, product 10, squares 4 and 25. Thursday, 26 and 150: both exactly on their means, so the row is all zeros, and the day contributes nothing to any sum. Friday, 28 and 165: 2 and 15, product 30, squares 4 and 225. Saturday, 30 and 170: 4 and 20, product 80, squares 16 and 400. Sunday, 32 and 180: 6 and 30, product 180, squares 36 and 900.

Now add the columns. The products add to 240 + 80 + 10 + 0 + 30 + 80 + 180 = Sxy = 620. The squared temperature deviations add to 36 + 16 + 4 + 0 + 4 + 16 + 36 = Sxx = 112. The squared sales deviations add to 1600 + 400 + 25 + 0 + 225 + 400 + 900 = Syy = 3550. Every product is positive, because on every day the two variables sit on the same side of their means. That is already the answer in miniature: they move together.

Finish the formula. Sxx times Syy is 112 × 3550 = 397,600. Its square root is 630.56. Divide: 620 ÷ 630.56 = r = 0.9833. A correlation of 0.98 is about as strong as real data gets. The stall owner can plan on it: hotter afternoons sell more tubs, almost without exception, at least across this kind of week.

Reading r: how strong is strong

The sign of r says the direction. Positive means the two climb together; negative means one falls as the other climbs. The size says the strength, and a rough vocabulary runs like this: 0.00 to 0.10 is negligible, 0.10 to 0.39 is weak, 0.40 to 0.69 is moderate, 0.70 to 0.89 is strong, and 0.90 and up is very strong. The stall's 0.9833 sits at the top of the scale. Treat the bands as words, not grades. A correlation of 0.3 can matter a lot in medicine and mean little in physics. Context decides what counts as strong.

Square r and the number gains a plain reading. r² is the share of the variation in one variable tracked by its straight-line relationship with the other. Here 0.9833 squared is 0.967, so about 96.7% of the day-to-day variation in tubs sold is tracked by temperature, in the linear sense. The remaining 3.3% is everything else: the day of the week, a school trip, a rival stall closing early. That reading belongs to r², not to r itself. Do not report 0.98 as 98% of anything. Square first.

A negative correlation, worked briefly

Negative correlations work the same way, with the sign flipped. Six friends log weekly exercise hours (0, 1, 2, 3, 4, 5) and their resting heart rates (76, 74, 71, 69, 66, 64 beats a minute). The means are 2.5 hours and 70 beats. The products of the deviations add to Sxy = −43, because on every pair the two variables sit on opposite sides of their means. Sxx is 17.5 and Syy is 106. So r = −43 ÷ √(17.5 × 106) = −43 ÷ 43.07 = −0.9984.

The minus sign says the relationship runs downhill: more exercise goes with a lower resting heart rate. The size, 0.9984, says it is nearly perfect. A negative correlation near −1 is just as strong as a positive one near 1. Strength lives in the size of the number, not in its sign, and −0.9984 is stronger than +0.5 by a long way. Beginners read the minus as weakness. It is not weakness. It is direction.

One wild day can move r

Now give the stall an eighth day. The temperature hits 38 degrees, the hottest of the summer, and the stall sells only 190 tubs. Not because the heat failed, but because the freezer ran dry by noon and the stall closed early. Add that day and the means move to 27.5 degrees and 155 tubs. The sums become Sxy = 1040, Sxx = 238 and Syy = 4950. The correlation falls to r = 1040 ÷ √(238 × 4950) = 1040 ÷ 1085.40 = 0.9582.

One day moved r from 0.9833 to 0.9582. The relationship did not change. The data gained a point that does not belong to the same story: a stock-out, not a weather effect. This is why every correlation starts with a plot. A single point far from the cloud can drag the number a long way, and the table alone will not warn you. Know what each point is before you trust the summary. The correlation calculator plots the scatter beside the number for exactly this reason.

The same calculation in a spreadsheet

Excel and Google Sheets both carry the correlation as one function. Put the temperatures in A2:A8 and the sales in B2:B8, then type =CORREL(A2:A8, B2:B8). The answer is 0.9833, the same as the hand table. For r squared, type =RSQ(B2:B8, A2:A8), which returns 0.967. The functions take the two columns in either order: the correlation of x with y is the correlation of y with x, which the formula shows, since Sxy is symmetric. Check the function against one hand calculation first, the 0.9833 or the 0.9582 above, and then trust it for the long lists.

When Pearson is the wrong tool

Pearson only sees straight lines. A relationship that climbs steadily but curves, like learning that rises fast at first and then levels off, can score a modest Pearson r while being perfectly steady in order. When the order is what matters, or the data are ranks to begin with, Spearman's rank correlation is the better tool: it correlates the ranks instead of the raw values.

Five students are ranked by revision hours, 1 to 5, and by exam marks their ranks come out 3, 1, 4, 2, 5. The rank differences are −2, 1, −1, 2 and 0. Square them: 4, 1, 1, 4, 0, which add to 10. Spearman's rho is 1 − (6 × 10) ÷ (5 × 24) = 1 − 0.5 = 0.5. The order climbs together only moderately, even though the top reviser is also the top scorer. Pearson on the raw marks would answer a different question, about equal gaps between scores, and on ranked data that question is the wrong one. The Spearman correlation calculator runs the same ranking on your data.

Watch out

Three slips cause nearly every wrong reading of a correlation. First, reporting r as a percentage: 0.98 is not 98% of anything, and the share of variation is r squared, 96.7% here. Second, quoting r without looking at the plot: a perfect curve can score near zero, and one wild point can move the number a long way. Third, reading causation into the number: ice cream sales and sunburn both rise with temperature, and neither causes the other. The heat drives both. When two variables move together, ask what third thing might be moving them, and read the correlation versus causation guide before making any claim.

That is the whole method. Centre each variable on its mean, multiply the deviations, add the three sums, divide. Run any of these numbers through the correlation calculator and it will agree: the tool shows the same ice cream answer, 0.9833, with the scatter plot beside it.

Frequently asked questions

How do I calculate correlation by hand?

Build a table with one row per pair: the two deviations from their means, their product, and the two squared deviations. Add the three columns to get Sxy, Sxx and Syy, then use r = Sxy divided by the square root of Sxx times Syy. For seven days of temperature and ice cream sales, Sxy is 620, Sxx is 112 and Syy is 3550, so r is 620 divided by 630.56, which is 0.9833.

How do I calculate correlation in Excel?

Put one variable in a column and the other in the next, then use =CORREL(first range, second range). For the ice cream example, =CORREL(A2:A8, B2:B8) returns 0.9833, the same as the hand table. For r squared, use =RSQ(B2:B8, A2:A8), which returns 0.967. Google Sheets has the same functions. Check the result against one hand calculation first.

What does a negative correlation mean?

It means the two variables move in opposite directions: as one rises, the other falls. Weekly exercise hours against resting heart rate gives r = -0.9984: more exercise goes with a lower heart rate. The minus sign is direction, not weakness: -0.9984 is far stronger than +0.5, because strength lives in the size of the number.

When should I use Spearman instead of Pearson?

When the data are ranks, or the relationship climbs steadily but curves instead of running straight. Spearman correlates the ranks, so equal gaps between raw scores do not matter. Five students ranked by revision hours and by exam marks give rho = 0.5: the order climbs together only moderately. Pearson is the default for two continuous variables with a roughly straight-line relationship.

Why did my correlation change when I added one data point?

Because one point far from the cloud can drag r a long way. Adding a 38-degree day when the stall sold only 190 tubs, after running out of stock, moved the ice cream correlation from 0.9833 to 0.9582. The relationship did not change; the data gained a point from a different story. Plot the data first and know what each point is before trusting the summary.