Seven students record how many hours they studied for a statistics exam and the score they got: (2, 58), (3, 65), (4, 60), (5, 68), (6, 66), (7, 77) and (8, 82). More study clearly goes with higher marks, but not perfectly — the student who studied four hours did worse than the one who studied three, and the six-hour student did worse than the five-hour one. The correlation coefficient compresses all of this into a single number. For these seven students it is .
So what does r mean? The Pearson correlation coefficient is a number between and that measures the strength and direction of a linear relationship between two variables. Positive values mean the variables tend to rise together, negative values mean one tends to fall as the other rises, and the closer is to , the more tightly the points hug a straight line. For pairs with means and , the formula is
An equivalent and often more illuminating form says that is the average product of z-scores. Using the sample standard deviations and , which divide by , and writing and ,
The here must match the inside and ; if you use the population versions that divide by , you divide by outside as well, and the factors cancel to give exactly the same . The rest of this article shows how to calculate the correlation coefficient by hand, how to read it, why it can never escape the interval from to , how it connects to regression and , where it misleads, and when to use Spearman rank correlation instead.
How do you calculate the correlation coefficient?
Work through the study-hours data in four steps. The means are hours and points.
| Student | Hours | Score | |||||
|---|---|---|---|---|---|---|---|
| A | 2 | 58 | 30 | 9 | 100 | ||
| B | 3 | 65 | 6 | 4 | 9 | ||
| C | 4 | 60 | 8 | 1 | 64 | ||
| D | 5 | 68 | 0 | 0 | 0 | 0 | 0 |
| E | 6 | 66 | 1 | 1 | 4 | ||
| F | 7 | 77 | 2 | 9 | 18 | 4 | 81 |
| G | 8 | 82 | 3 | 14 | 42 | 9 | 196 |
| Sum | 35 | 476 | 0 | 0 | 102 | 28 | 454 |
Step 1: deviations. Subtract the mean from every value. The deviations in each column add to zero, which is a useful arithmetic check.
Step 2: products. Multiply each pair of deviations. A product is positive when a student is above average on both variables or below average on both, and negative when they are above on one and below on the other. Student E, who studied more than average but scored below it, contributes the only negative product. The sum of products is .
Step 3: sums of squares. Square the deviations and add: and .
Step 4: divide.
Now check it with the z-score form. The sample standard deviations are hours and points (see the standard deviation article for why the divisor is ). Student G, for example, has and , so contributes to the sum. Adding all seven products of z-scores gives , and dividing by gives again. The two forms are the same calculation arranged differently.
What does r mean? Reading the scatter plot
The best way to build intuition for is to look at what different values look like. Each panel below contains eleven points, and the number underneath is the exact Pearson correlation of those points.
Figure 1 — Six scatter plots of eleven points each, with the exact Pearson correlation of the plotted points under each panel. The first five were constructed so that r takes exactly the value shown. The sixth is y = x² for x from −5 to 5: y is completely determined by x, yet r is exactly zero, because the relationship is not a line.
Notice that looks much weaker than most people expect, and that is still visibly imperfect — our seven students sit at about this level. The red panel is the most important one in the figure: a correlation of zero means no straight-line trend, not no relationship. The left half of the parabola has a strong negative slope, the right half an equally strong positive one, and the two cancel exactly. In symbols, with symmetric about 0, .
What is a strong correlation, and what is a weak one?
Introductory courses usually offer a verbal scale along these lines, applied to the absolute value :
| Absolute value of r | Common description |
|---|---|
| 0.00 to 0.19 | very weak or none |
| 0.20 to 0.39 | weak |
| 0.40 to 0.69 | moderate |
| 0.70 to 0.89 | strong |
| 0.90 to 1.00 | very strong |
Treat this as a convention, not a law. The boundaries vary from textbook to textbook, and the right standard depends heavily on the field. In the behavioural sciences, Jacob Cohen’s Statistical Power Analysis for the Behavioral Sciences (2nd edition, 1988) proposed , and as small, medium and large effects, and Cohen himself stressed that these labels were relative to the area of research. Later surveys of published findings suggest even his benchmarks are demanding: Gignac and Szodorai (2016), analysing 708 meta-analytic correlations in individual-differences research, suggested 0.10, 0.20 and 0.30 as relatively small, typical and relatively large. At the opposite end, a calibration curve in analytical chemistry with would usually be considered poor.
A more honest translation of strong vs weak correlation is through , discussed below: corresponds to a straight line explaining only of the variance, to , and to . And whatever the label, the sample size matters as much as the value — a point we return to when asking whether is significant.
Why is r always between −1 and 1?
Collect the deviations into two vectors, and . Then the numerator of is the dot product and the denominator is the product of the lengths :
The Cauchy–Schwarz inequality states that , with equality exactly when one vector is a scalar multiple of the other. Dividing through gives , and equality holds precisely when for every — that is, when all the points lie on one straight line, with for positive and for negative .
The same expression has a geometric reading. In any inner-product space, , so
where is the angle between the two centred data vectors in -dimensional space (the idea is developed in our article on vector spaces). Perfect positive correlation means the vectors point the same way; means they are perpendicular; means opposite directions. For the seven students the deviation vectors are and , and .
Covariance vs correlation: why r has no units
The numerator of , divided by , is the sample covariance:
Covariance has the right sign but an unusable size, because it carries the units of both variables. Measure study time in minutes instead of hours and every deviation is multiplied by 60, so the covariance becomes minute-points. Nothing about the students has changed. Dividing by the standard deviations removes the units:
In minutes, becomes and the ratio is — the same number. In general, if and , then
Shifting either variable changes nothing, because shifts vanish when you subtract the mean. Multiplying by a positive constant changes nothing, because the constant appears in both the numerator and the denominator. Multiplying by a negative constant flips the sign and nothing else. A worked check: suppose each student had ten hours available for either study or leisure, so leisure hours are . The leisure deviations are the study deviations with their signs reversed, so becomes while stays at 28, and the correlation between leisure and score is .
r vs r squared: how correlation connects to regression
The least-squares line for predicting from has slope , derived in our article on how linear regression works. Since , the slope can be written
For the students, points per hour, and indeed . The intercept is , so the fitted line is . The formula says something memorable: in standard-deviation units, the predicted moves only standard deviations for each standard deviation of . Because whenever the points are not on a perfect line, predictions are always pulled toward the mean — the phenomenon Galton called regression, covered in regression to the mean.
Now the difference between and . Split the total variation in scores, , into the part the line reproduces and the part left over:
The share explained is
and as well. For simple linear regression with one predictor, exactly: , which is the square of . So means a straight line in study hours accounts for about of the variance in scores, and is left to everything else.
The two numbers carry different information. keeps the direction and is symmetric in and ; loses the sign but reads directly as a proportion of variance. Symmetry has a neat consequence: the slope for predicting hours from score is hours per point, and the product of the two slopes is .
What can the correlation coefficient miss?
A single number cannot describe a scatter plot, and fails in several characteristic ways.
Non-linear relationships. The parabola in Figure 1 has . A relationship that rises and then levels off will typically have a positive but understated .
Anscombe’s quartet. Francis Anscombe’s 1973 paper “Graphs in Statistical Analysis” in The American Statistician presented four datasets of eleven points each with near-identical summaries: mean of equal to 9, mean of about 7.50, the same regression line , and correlation 0.816 (0.817 in the fourth set). For the first set, , and , giving . Plotted, the four are a noisy line, a smooth curve, a perfect line with one outlier, and a vertical stack of ten points plus one far-off point that single-handedly creates the correlation. The lesson is the same as the parabola’s: plot first.
Outliers. Add an eighth student to our data who studied 12 hours and scored 50. The sums become , and , so
One point out of eight has turned a correlation of into essentially zero. Because is built from products of deviations, a point far from both means carries enormous weight. The Spearman version discussed below falls from to — also damaged, but far less.
Restricted range. If you only observe part of the range of , the correlation shrinks even when the underlying relationship is unchanged. For a bivariate normal population with correlation , keeping only the cases where is more than one standard deviation above its mean reduces the standard deviation of to about of its original value, and the correlation within that group falls to
when , where is that ratio of standard deviations. This is why admission test scores often correlate weakly with performance among admitted students: the selection removed the low scorers whose results would have shown the relationship.
Groups and aggregates. A correlation computed on pooled data can reverse within every subgroup, as in Simpson’s paradox. Correlations between group averages can also differ wildly from correlations between individuals. W. S. Robinson’s 1950 paper “Ecological Correlations and the Behavior of Individuals” showed that across US states in the 1930 census the share of foreign-born residents correlated negatively with illiteracy (he reported ; a 2011 re-examination found with corrected data), while for individuals the correlation between being foreign-born and being illiterate was positive, about . Immigrants tended to settle in states with good schooling. Inferring individual behaviour from an aggregate correlation is the ecological fallacy.
Pearson vs Spearman rank correlation, and Kendall’s tau
Pearson’s asks whether the points lie near a straight line. Often the question you actually care about is whether tends to increase as increases, whatever the shape. Spearman rank correlation answers that: replace each by its rank among the values, each by its rank among the values, and compute Pearson’s on the ranks. With no ties this simplifies to
where is the difference between the two ranks of observation .
Take and , so . Every increase in produces an increase in ; the relationship is perfectly monotonic but strongly curved. Pearson’s calculation gives , and , so
The ranks of and are identical, every , and Spearman’s exactly. Pearson is penalising the curve; Spearman is not.
For the seven students, the score ranks are 1, 3, 2, 5, 4, 6, 7 against hour ranks 1 to 7. The squared rank differences add to 4, so , close to Pearson’s 0.905, as expected for data that are roughly linear.
Kendall’s tau, introduced by Maurice Kendall in Biometrika in 1938, takes a different route to the same goal. Look at every pair of observations and call it concordant if the one with larger also has larger , discordant if not. Then
The students form 21 pairs, of which only two are discordant (B with C, and D with E), so . Kendall’s tau has a direct probabilistic reading: the probability that a random pair is concordant minus the probability that it is discordant.
Use Pearson when the relationship looks linear and there are no gross outliers; it is also the quantity tied to regression and . Use Spearman or Kendall for ordinal data such as rankings or rating scales, for monotonic curves, or when outliers are a worry.
Is the correlation significant?
Even if two variables are completely unrelated, a small sample will rarely give exactly zero. The standard test of the null hypothesis of zero correlation uses
which follows a distribution with degrees of freedom when the null hypothesis is true and the data are bivariate normal. For the students,
With 5 degrees of freedom, the two-sided p-value is about . (For an odd number of degrees of freedom the distribution has a closed-form CDF, which gives this value directly; it agrees with the table bracket of .) The same statistic tests whether the regression slope is zero: divided by its standard error is again . See p-values explained for what this number does and does not mean.
A p-value says nothing about how precisely has been estimated. Fisher’s transformation is approximately normal with standard error . Here and the standard error is , so a 95 percent interval for is , which transforms back to roughly to for the correlation. Seven students are enough to say the correlation is positive, but not enough to say whether it is moderate or very strong.
The deeper warning is that small samples produce large correlations by chance. For independent pairs from a bivariate normal distribution, has density proportional to . With that is , which can be integrated by hand, and the results are sobering:
- half of all samples give above about ;
- about give ;
- exactly give , which is therefore the critical value at the 5 percent level;
- about give .
So among ten independent variables measured on ten people, you should expect around six of the 45 pairs to show a “moderate” correlation above 0.5 with nothing behind them. The 5 percent critical value shrinks as grows: for , for , for . With enough data, a tiny correlation becomes statistically significant without becoming important — significance and strength are different questions.
Does correlation imply causation?
No, and the reasons are catalogued in detail in our article on correlation vs causation: the arrow may point the other way, a third variable may drive both, the sample may have been selected in a way that manufactures the association, or the pattern may be a coincidence found by searching many pairs.
One mechanism deserves a computed example here, because it defeats the significance test above: shared drift over time. Build two random walks from digits that have nothing to do with each other. Walk A starts at 0 and steps up for each even digit among the first twenty decimal digits of , down for each odd one; walk B does the same with the first twenty decimal digits of . Walk A drifts down to and ends at ; walk B drifts up and ends at . The correlation between their twenty positions is
and the naive test gives with 18 degrees of freedom, a p-value below . Yet the step sequences themselves correlate at only , well inside the critical value of for . The test assumes independent observations, and the positions of a random walk are anything but independent: each position contains all the previous steps. Correlating the changes rather than the levels is the first defence against this kind of spurious correlation in time series.
Who invented the correlation coefficient?
The idea came from heredity. Francis Galton, who had been studying how the heights of children relate to those of their parents, sent the Royal Society a paper in December 1888 titled “Co-relations and their Measurement, chiefly from Anthropometric Data”, published in its Proceedings. He observed that once each measurement — height, forearm length, head length — was expressed in units of its own variability, the regression of one on another had a single slope that measured the strength of the “co-relation” between them. This was the first general method for attaching a number to the association between two variables.
Karl Pearson gave the coefficient its modern product-moment form. The formula appears in his short “Note on Regression and Inheritance in the Case of Two Parents” (Proceedings of the Royal Society, 1895) and is developed at length in “Mathematical Contributions to the Theory of Evolution. III. Regression, Heredity, and Panmixia”, published in the Philosophical Transactions in 1896. The name “Pearson correlation” records that work.
Priority is murkier than the name suggests. The French physicist Auguste Bravais, in a memoir on the probabilities of errors in the position of a point printed in 1846 (and sometimes dated 1844), worked with the two-dimensional normal distribution and wrote down an expression equivalent to the product-moment coefficient, though not as a measure of association in its own right. Pearson initially credited Bravais, then in “Notes on the History of Correlation” (Biometrika, 1920) argued that Bravais had added little beyond Gauss and that the concept belonged to Galton. Historians still debate how much credit each deserves.
Rank methods followed. Charles Spearman introduced rank correlation in “The Proof and Measurement of Association between Two Things”, published in the American Journal of Psychology in 1904, and Kendall’s tau appeared in 1938.
Back to the seven students. Their correlation of says that hours and scores line up closely along a straight line; says that line accounts for about four-fifths of the variation; says the pattern is unlikely to be chance; and the interval from about to says that seven students cannot pin it down much further. None of it says that studying caused the scores, and one wild data point could erase it. The correlation coefficient is useful precisely because it is so simple — and for the same reason, it should never be read without the scatter plot beside it.
Related topics: Correlation vs Causation, How Linear Regression Works, Standard Deviation, Regression to the Mean, Cauchy–Schwarz Inequality, Vector Spaces, P-Values Explained, Simpson’s Paradox and Causality, Random Walks, Why Divide by n Minus 1
Frequently asked
What is a correlation coefficient?
A correlation coefficient is a single number between −1 and 1 that summarises how closely two variables follow a straight-line relationship. The sign gives the direction: positive when the variables rise together, negative when one rises as the other falls. The size gives the strength: 1 or −1 means every point lies exactly on a line, and 0 means there is no linear trend at all. The usual version is Pearson's r.
How do you calculate the correlation coefficient?
Find the mean of x and the mean of y. For each pair, compute the deviation of x from its mean and of y from its mean, multiply them, and add up the products. Divide that sum by the square root of the sum of squared x deviations times the square root of the sum of squared y deviations. For seven students with study hours 2 to 8 and scores 58, 65, 60, 68, 66, 77 and 82, the sum of products is 102, the two sums of squares are 28 and 454, and r is 102 divided by about 112.75, which is 0.90.
What is considered a strong correlation?
There is no universal cut-off. A common rule of thumb calls an absolute value of r above about 0.7 strong, 0.4 to 0.7 moderate and below 0.4 weak, but these are conventions. In the behavioural sciences Jacob Cohen proposed 0.10, 0.30 and 0.50 as small, medium and large, while in physics or engineering a correlation of 0.9 between a measurement and a prediction can be disappointing. Always judge r against the field, the sample size and the scatter plot.
What is the difference between r and r squared?
r is the correlation coefficient: it has a sign and runs from −1 to 1. r squared is its square, runs from 0 to 1, and in simple linear regression equals the proportion of the variance in y that the fitted line accounts for. A correlation of 0.9 gives r squared of 0.81, so the line explains 81 percent of the variation; a correlation of 0.5 explains only 25 percent, which is why r values sound more impressive than they are.
Does correlation imply causation?
No. A correlation shows that two variables move together, not why. The link could run in either direction, both could be driven by a third variable, the sample could have been selected in a way that creates the pattern, or the two series could simply share a trend over time. Establishing causation needs a design, such as a randomised experiment or a credible natural experiment, that rules those alternatives out.
What is the difference between Pearson and Spearman correlation?
Pearson correlation measures how well the data fit a straight line and uses the actual values. Spearman rank correlation replaces each value by its rank and then computes Pearson's r on the ranks, so it measures how well the data fit any steadily increasing or decreasing curve. For x from 1 to 8 and y equal to 2 to the power x, Pearson's r is 0.85 but Spearman's rho is exactly 1. Spearman is also far less affected by a single outlier.