Instant PDF download, name-and-email checkout. Complete Book Bundle: every Economics, Statistics, Mathematics, Econometrics and Research Methods book
Statistics

How to Calculate the Correlation Coefficient r by Hand, and How to Interpret It

Learn to calculate the correlation coefficient r by hand, step by step, and interpret its sign and strength, with worked examples and practice questions.

In 30 seconds
  • The correlation coefficient \(r\) measures the direction and strength of a linear relationship between two quantitative variables. It always lies between \(-1\) and \(+1\).
  • By hand, find each point’s deviation from the means, multiply the deviations in pairs, add them up, and divide by \(\sqrt{S_{xx}S_{yy}}\).
  • In our case, eight students’ revision hours and test scores give \(S_{xy} = 288\), \(S_{xx} = 92\), \(S_{yy} = 921.5\), so \(r = 0.989\): a very strong positive linear relationship.
  • \(r\) has no units, does not change if you swap \(x\) and \(y\) or change units, but is badly distorted by outliers and is useless for curved patterns.
  • Exam point: always describe a correlation with three words in context (direction, strength, form), and draw or imagine the scatterplot before trusting \(r\).

The case: does more revision go with higher marks?

A maths teacher asks eight students in her class to log how many hours they revised in the week before a test. After marking, she puts the hours next to each student’s percentage score:

StudentABCDEFGH
Revision hours, \(x\)2356891112
Test score (%), \(y\)5255616070747884

Looking down the table, scores clearly tend to rise with hours. But “tend to rise” is vague. The teacher wants one number that says how closely the points follow a straight line, so she can compare this class with last year’s, or compare revision hours with other possible predictors such as sleep or attendance. (The figures are illustrative.)

That number is the correlation coefficient \(r\). In this post we calculate it by hand from first principles, check the answer with a second formula, and then learn what the value does and does not tell us.

The concept: what r measures and where the formula comes from

Start with a scatterplot. Draw a vertical line at the mean of \(x\) and a horizontal line at the mean of \(y\). These two lines split the plot into four quadrants. If the relationship is positive, most points sit in the top-right quadrant (above-average \(x\) with above-average \(y\)) and the bottom-left quadrant (below-average with below-average).

For each point, the deviation \(x – \bar x\) says how far it lies to the right or left of the mean, and \(y – \bar y\) says how far it lies above or below. The product \((x – \bar x)(y – \bar y)\) is positive in the top-right and bottom-left quadrants, and negative in the other two. Adding up all the products therefore measures whether the points lean one way or the other.[1]

The sum of products on its own depends on the units: measuring time in minutes instead of hours would multiply it by 60. To remove the units, we divide by a quantity with the same units, built from the spread of each variable. The result is the correlation coefficient.

Key termCorrelation coefficient (Pearson’s r): a number between \(-1\) and \(+1\) that measures the direction and strength of the linear relationship between two quantitative variables. Values near \(+1\) mean the points lie close to an upward-sloping line; values near \(-1\) mean they lie close to a downward-sloping line; values near 0 mean there is no linear pattern.
\[ r = \frac{S_{xy}}{\sqrt{S_{xx}\,S_{yy}}}, \quad S_{xy} = \sum (x-\bar x)(y-\bar y),\ \ S_{xx} = \sum (x-\bar x)^2,\ \ S_{yy} = \sum (y-\bar y)^2 \]

Here \(\bar x\) and \(\bar y\) are the sample means. \(S_{xy}\) is the sum of the products of deviations: it carries the sign of the relationship. \(S_{xx}\) and \(S_{yy}\) are the sums of squared deviations of \(x\) and of \(y\), which measure each variable’s spread. Dividing by \(\sqrt{S_{xx}S_{yy}}\) scales the answer so it always falls between \(-1\) and \(+1\). This \(S\) notation is widely used in British textbooks and calculator work.[3]

Statistics Made Simple textbook coverStatistics Made Simple explains correlation and the correlation coefficient with worked examples, diagrams and tables.Get the textbook · $15

Two equivalent forms are worth knowing. AP Statistics writes \(r\) as the average product of z-scores:

\[ r = \frac{1}{n-1}\sum \left(\frac{x_i – \bar x}{s_x}\right)\left(\frac{y_i – \bar y}{s_y}\right) \]

where \(s_x\) and \(s_y\) are the sample standard deviations. Each bracket is a z-score, which is why \(r\) has no units.[2] For calculator work with summary statistics, the “computational” forms avoid deviations altogether: \(S_{xx} = \sum x^2 – (\sum x)^2/n\), \(S_{yy} = \sum y^2 – (\sum y)^2/n\) and \(S_{xy} = \sum xy – (\sum x)(\sum y)/n\). All three routes give exactly the same \(r\).

Why this method fits the case

The correlation coefficient is the right summary for the revision data because:

  • Both variables are quantitative. Hours and percentage scores are measured on number scales, so deviations and products make sense.
  • The scatterplot looks roughly linear. The scores rise by a fairly steady amount for each extra hour, with no obvious bend.
  • There are no extreme outliers. Every student sits near the general pattern.
  • We want a single, unit-free measure of strength. \(r\) lets the teacher compare this relationship with others measured in different units.

It is not the right tool when:

  • One or both variables are categorical (for example, school attended). Use a two-way table instead.
  • The pattern is curved. A U-shaped or levelling-off pattern can have a small \(r\) even when the relationship is very strong.
  • The data are ranks, or the relationship is monotonic but not linear. Spearman’s rank correlation coefficient is then more suitable.
  • You want to predict \(y\) from \(x\). Correlation measures strength; prediction needs the least-squares regression line.
  • You want to claim that \(x\) causes \(y\). Correlation alone cannot show that; see our post on correlation vs causation.

Setting it up

The neatest hand layout is a table with one row per student and columns for the deviations, their squares and their products. First find the means: \(\bar x = 56/8 = 7\) hours and \(\bar y = 534/8 = 66.75\)%.

Student\(x\)\(y\)\(x – \bar x\)\(y – \bar y\)\((x-\bar x)^2\)\((y-\bar y)^2\)\((x-\bar x)(y-\bar y)\)
A252−5−14.7525217.562573.75
B355−4−11.7516138.062547.00
C561−2−5.75433.062511.50
D660−1−6.75145.56256.75
E87013.25110.56253.25
F97427.25452.562514.50
G1178411.2516126.562545.00
H1284517.2525297.562586.25
Total565340092921.5288

Two built-in checks: the deviation columns must each add to zero (they do), and every product in the last column is positive, because every student is either above average on both variables or below average on both. That already tells us \(r\) will be positive and large.

Solving it

Worked example

Use the deviation table to calculate the correlation coefficient between revision hours and test score.

Step 1 Read the totals: \(S_{xx} = 92\), \(S_{yy} = 921.5\), \(S_{xy} = 288\).
Step 2 Multiply the two sums of squares: \(S_{xx}S_{yy} = 92 \times 921.5 = 84\,778\).
Step 3 Square root: \(\sqrt{84\,778} \approx 291.17\).
Step 4 Divide: \(r = 288 / 291.17 \approx 0.989\).

\(r \approx 0.989\): there is a very strong, positive, linear relationship between revision hours and test score for these eight students.

Worked example

Check the answer using summary statistics only: \(n = 8\), \(\sum x = 56\), \(\sum y = 534\), \(\sum x^2 = 484\), \(\sum y^2 = 36\,566\), \(\sum xy = 4026\).

Step 1 \(S_{xx} = 484 – 56^2/8 = 484 – 392 = 92\).
Step 2 \(S_{yy} = 36\,566 – 534^2/8 = 36\,566 – 35\,644.5 = 921.5\).
Step 3 \(S_{xy} = 4026 – (56)(534)/8 = 4026 – 3738 = 288\).
Step 4 \(r = 288/\sqrt{92 \times 921.5} \approx 0.989\), as before.
Step 5 z-score check: \(s_x = \sqrt{92/7} \approx 3.625\) and \(s_y = \sqrt{921.5/7} \approx 11.474\). The sum of z-score products is about 6.924, and \(6.924/7 \approx 0.989\).

All three methods agree, so we can be confident that \(r = 0.989\) to three decimal places.

Worked example

A ninth student, I, revised for 14 hours but scored only 50% (she was ill on the day). Add her to the data. What happens to \(r\)? (The figures are illustrative.)

Step 1 New totals: \(n = 9\), \(\sum x = 70\), \(\sum y = 584\), \(\sum x^2 = 680\), \(\sum y^2 = 39\,066\), \(\sum xy = 4726\).
Step 2 \(S_{xx} = 680 – 70^2/9 \approx 135.56\); \(S_{yy} = 39\,066 – 584^2/9 \approx 1170.89\); \(S_{xy} = 4726 – (70)(584)/9 \approx 183.78\).
Step 3 \(r = 183.78/\sqrt{135.56 \times 1170.89} \approx 183.78/398.40 \approx 0.461\).

One unusual point cuts \(r\) from 0.989 to 0.461. Correlation is not resistant: always look at the scatterplot and ask whether a single point is driving the value.

Statistics Made Simple Practice Questions coverMake calculating r automatic with the Practice Questions book: 1,569 questions, all fully worked.Get 1,569 questions · $9

What the answer tells us

A value of \(r = 0.989\) says the eight points lie very close to a straight, upward-sloping line. Figure 1 shows why. With the mean lines drawn in, every point sits in either the top-right or the bottom-left quadrant, so every product of deviations is positive and nothing cancels out.

Revision hours and test scores (eight students)
StudentsMean lines
4550556065707580859002468101214Revision hours, xTest score (%), ymean hours = 7mean score = 66.75both above: product +both below: product +
Figure 1. Every point lies in the top-right or bottom-left quadrant formed by the mean lines, so every product of deviations is positive. The points sit close to a straight line, giving r = 0.989.

How to describe it. A complete description uses direction, strength and form, in context: “There is a strong, positive, linear relationship between hours of revision and test score.” Rough guides to strength are often quoted (for example, \(|r| > 0.8\) strong, 0.5 to 0.8 moderate, below 0.5 weak), but these are conventions, not rules. In some sciences \(r = 0.6\) is impressive; in physics experiments it would be poor.

Reasonableness check. The value must be between \(-1\) and \(+1\); 0.989 is. Its sign matches the scatterplot. And the size is plausible: the scores rise by roughly 3 marks per extra hour, with no student more than about 4 marks away from that trend.

What r does not change with. If the teacher records time in minutes, every \(x\) is multiplied by 60. Deviations scale by 60 too, and the 60 cancels between top and bottom, so \(r\) stays 0.989. Adding a constant (say 5 bonus marks to everyone) shifts the mean by the same amount, leaving deviations, and hence \(r\), unchanged. Swapping \(x\) and \(y\) also leaves \(r\) unchanged, because the formula is symmetric.[4]

What r is sensitive to. The third worked example shows one outlier can halve \(r\). An outlier in the direction of the pattern can do the reverse: if a ninth student had revised for 20 hours and scored 100%, \(r\) would rise slightly to about 0.990, making the relationship look even stronger than the main group suggests. Curved patterns are the other trap. If test scores rise and then fall with hours of sleep, for instance 55, 66, 73, 76, 73, 66, 55 for 4 to 10 hours, then \(r = 0\) exactly, even though sleep clearly matters. Zero correlation means no linear relationship, not no relationship.

The link to \(r^2\). Squaring gives \(r^2 \approx 0.978\). In the next topic, the least-squares regression line, this becomes the proportion of the variation in scores that is explained by the straight-line relationship with hours.

Common mistakeDividing by \(S_{xx}S_{yy}\) instead of its square root. That gives \(288/84\,778 \approx 0.0034\), a tiny number that should immediately look wrong for points that so obviously lie on a line. Always check that your answer agrees with the scatterplot.
Common mistakeCalling a correlation “strong” because the relationship is steep. Strength is about how closely the points hug a line, not the slope of that line. A shallow line with points tightly packed around it has \(r\) near 1; a steep line with points widely scattered can have a modest \(r\).
Exam tipShow the intermediate values \(S_{xx}\), \(S_{yy}\) and \(S_{xy}\) (or the table of deviations) even when your calculator gives \(r\) directly. Method marks are usually attached to these. Then interpret in context, using “linear” and both variable names. If the question supplies summary statistics, use the computational forms rather than reconstructing the data.

The Statistics Made Simple textbook covers scatterplots, correlation and regression with worked examples and clear diagrams. To build speed with the formulas and the interpretation sentences examiners want, try the Statistics Made Simple Practice Questions book, which includes many fully worked correlation questions from raw data and from summary statistics.

Statistics Made Simple bundle coverMaster correlation and regression with both Statistics Made Simple books for $19.Both books · $19

Practice questions

Give \(r\) to three decimal places unless told otherwise.

EasyQ1. For a sample of used cars, the correlation between age (years) and price (£) is \(r = -0.82\). Interpret this value. Show worked answer
There is a strong, negative, linear relationship between a car’s age and its price.
Older cars in the sample tend to have lower prices, and the points lie fairly close to a downward-sloping line.
EasyQ2. Given \(S_{xx} = 30\), \(S_{yy} = 90\) and \(S_{xy} = 45\), find \(r\). Show worked answer
\(r = 45/\sqrt{30 \times 90} = 45/\sqrt{2700} = 45/51.96 \approx 0.866\).
MediumQ3. Five days of data: price of a snack (in £), \(x\) = 1, 2, 3, 4, 5; number sold (dozens), \(y\) = 10, 8, 7, 4, 1. Calculate \(r\) using deviations. Show worked answer
\(\bar x = 3\), \(\bar y = 30/5 = 6\).
Deviations \(x – \bar x\): −2, −1, 0, 1, 2. Deviations \(y – \bar y\): 4, 2, 1, −2, −5.
\(S_{xx} = 4+1+0+1+4 = 10\); \(S_{yy} = 16+4+1+4+25 = 50\).
\(S_{xy} = -8 – 2 + 0 – 2 – 10 = -22\).
\(r = -22/\sqrt{500} = -22/22.36 \approx -0.984\): a very strong negative linear relationship.
MediumQ4. In the revision case, \(r = 0.989\). What is \(r\) if (a) time is measured in minutes, (b) the teacher adds 5 marks to every score, (c) score is plotted on the horizontal axis and hours on the vertical axis? Show worked answer
(a) 0.989: multiplying \(x\) by 60 multiplies \(S_{xy}\) by 60 and \(\sqrt{S_{xx}}\) by 60, which cancel.
(b) 0.989: adding a constant does not change any deviation.
(c) 0.989: the formula is symmetric in \(x\) and \(y\).
ExamQ5. For 10 summer days, the maximum temperature \(x\) (°C) and ice-cream sales \(y\) (dozens) give \(\sum x = 238\), \(\sum y = 426\), \(\sum x^2 = 6200\), \(\sum y^2 = 18\,752\), \(\sum xy = 10\,700\). (a) Calculate \(S_{xx}\), \(S_{yy}\) and \(S_{xy}\). (b) Calculate \(r\). (c) Interpret \(r\) in context. (d) A manager says this proves hot weather causes higher sales. Comment. [7] Show worked answer
(a) \(S_{xx} = 6200 – 238^2/10 = 6200 – 5664.4 = 535.6\). [1]
\(S_{yy} = 18\,752 – 426^2/10 = 18\,752 – 18\,147.6 = 604.4\). [1]
\(S_{xy} = 10\,700 – (238)(426)/10 = 10\,700 – 10\,138.8 = 561.2\). [1]
(b) \(r = 561.2/\sqrt{535.6 \times 604.4} = 561.2/568.96 \approx 0.986\). [2]
(c) Very strong positive linear relationship: hotter days tend to have higher ice-cream sales. [1]
(d) Correlation alone does not prove causation; this is observational data, and other factors (for example weekends or school holidays) may vary with temperature. [1]

Frequently asked questions

Why is r always between −1 and 1?

It follows from the Cauchy–Schwarz inequality: the sum of products of deviations can never exceed, in size, the square root of the product of the two sums of squares. The value \(\pm 1\) is reached only when every point lies exactly on a straight line.

Does r = 0 mean the variables are unrelated?

No. It means there is no linear relationship. The variables may have a strong curved relationship, as in the sleep example above, which gives \(r = 0\) despite a clear pattern. Always plot the data.

Should I use n or n − 1 in the z-score formula?

Use \(n – 1\) together with sample standard deviations \(s_x\) and \(s_y\) (also calculated with \(n – 1\)). If you use \(n\) in both places, the factors cancel and you get the same \(r\). What matters is consistency.

How is r different from the slope of the regression line?

The slope is measured in units of \(y\) per unit of \(x\) and can be any size. \(r\) has no units and lies between −1 and 1. They are linked by \(b = r\,s_y/s_x\), so they always have the same sign. For the basics of what correlation shows, see our post on the basics of correlation.

References

  1. Illowsky, B. & Dean, S. (2023) Introductory Statistics 2e. Houston, TX: OpenStax. https://openstax.org/details/books/introductory-statistics-2e
  2. College Board. AP Statistics Course and Exam Description. New York: College Board.
  3. Moore, D. S., McCabe, G. P. & Craig, B. A. Introduction to the Practice of Statistics. New York: W. H. Freeman.
  4. Agresti, A., Franklin, C. & Klingenberg, B. Statistics: The Art and Science of Learning from Data. Boston: Pearson.
Statistics Made Simple Complete Bundle cover showing both the textbook and practice book
This topic has a full chapter in Statistics Made Simple, with 1,569 worked practice questions in the bundle.Statistics Made Simple Complete Bundle — Textbook + 1,569 Practice Questions
Get it for $19
E

The EconTutorials team writes clear, exam-focused lessons in economics and statistics for A-Level, IB, AP and university students, with more than 13 years of classroom teaching behind every guide and book in the Made Simple series.