- 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:
| Student | A | B | C | D | E | F | G | H |
|---|---|---|---|---|---|---|---|---|
| Revision hours, \(x\) | 2 | 3 | 5 | 6 | 8 | 9 | 11 | 12 |
| Test score (%), \(y\) | 52 | 55 | 61 | 60 | 70 | 74 | 78 | 84 |
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.
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]
Two equivalent forms are worth knowing. AP Statistics writes \(r\) as the average product of z-scores:
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)\) |
|---|---|---|---|---|---|---|---|
| A | 2 | 52 | −5 | −14.75 | 25 | 217.5625 | 73.75 |
| B | 3 | 55 | −4 | −11.75 | 16 | 138.0625 | 47.00 |
| C | 5 | 61 | −2 | −5.75 | 4 | 33.0625 | 11.50 |
| D | 6 | 60 | −1 | −6.75 | 1 | 45.5625 | 6.75 |
| E | 8 | 70 | 1 | 3.25 | 1 | 10.5625 | 3.25 |
| F | 9 | 74 | 2 | 7.25 | 4 | 52.5625 | 14.50 |
| G | 11 | 78 | 4 | 11.25 | 16 | 126.5625 | 45.00 |
| H | 12 | 84 | 5 | 17.25 | 25 | 297.5625 | 86.25 |
| Total | 56 | 534 | 0 | 0 | 92 | 921.5 | 288 |
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
Use the deviation table to calculate the correlation coefficient between revision hours and test score.
\(r \approx 0.989\): there is a very strong, positive, linear relationship between revision hours and test score for these eight students.
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\).
All three methods agree, so we can be confident that \(r = 0.989\) to three decimal places.
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.)
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.
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.
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.
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.
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
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
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
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
(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
\(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
- Illowsky, B. & Dean, S. (2023) Introductory Statistics 2e. Houston, TX: OpenStax. https://openstax.org/details/books/introductory-statistics-2e
- College Board. AP Statistics Course and Exam Description. New York: College Board.
- Moore, D. S., McCabe, G. P. & Craig, B. A. Introduction to the Practice of Statistics. New York: W. H. Freeman.
- Agresti, A., Franklin, C. & Klingenberg, B. Statistics: The Art and Science of Learning from Data. Boston: Pearson.

