Pearson correlation:
measuring how closely two variables move together
A single number between −1 and +1 that tells you how tightly a scatter of points hugs a straight line.
Calcylator Editorial Team
Updated · 5 min read
The formula
Plot hours studied against exam score and the points drift up and to the right. Pearson's correlation coefficient, written r, puts a number on how neatly they follow a straight line. A value of +1 means a perfect rising line, −1 a perfect falling line, and 0 no linear relationship.
The coefficient describes linear association only. It says nothing about a curve, and it says nothing about cause. Two series can rise together because one drives the other, because a third factor drives both, or by coincidence.
- x̄, ȳ:
- the means of x and y
- Σ:
- sum over every pair of points
- Numerator:
- how x and y vary together
- Denominator:
- scales the result into −1 to +1
The numerator is a sum of products of deviations from the mean. If points above the x mean tend to sit above the y mean as well, the products are mostly positive and r is positive.
Worked example with five pairs
Take x = 1, 2, 3, 4, 5 and y = 2, 1, 4, 3, 5. Both means are 3.
| x | y | x − 3 | y − 3 | Product | (x − 3)² | (y − 3)² |
|---|---|---|---|---|---|---|
| 1 | 2 | −2 | −1 | 2 | 4 | 1 |
| 2 | 1 | −1 | −2 | 2 | 1 | 4 |
| 3 | 4 | 0 | 1 | 0 | 0 | 1 |
| 4 | 3 | 1 | 0 | 0 | 1 | 0 |
| 5 | 5 | 2 | 2 | 4 | 4 | 4 |
| Sum | 8 | 10 | 10 |
Σ products
8
Σ(x − x̄)²
10
Σ(y − ȳ)²
10
Denominator
√(10 × 10) = 10
Correlation coefficient
r = 0.80
8 ÷ 10 = 0.80, and r² = 0.64, so about 64% of the variation in y is accounted for by a straight-line fit to x.
Perfect, zero and misleading cases
For x = 1, 2, 3 and y = 2, 4, 6, every point lies exactly on y = 2x, so r = +1. Doubling the slope or adding a constant does not change r, because the coefficient is scale-free.
Now take x = −2, −1, 0, 1, 2 and y = x². There is a perfect, deterministic relationship, yet r = 0, because the pattern is a U rather than a line. A coefficient near zero rules out a linear link, not every link.
Outliers can rewrite the story
Add a sixth point to the five-pair data at x = 10, y = 1. The correlation drops from 0.80 to about −0.14, flipping sign because one extreme point dominates the sums. Add instead a sixth point at x = 10, y = 10 and r climbs to 0.96, an apparent near-perfect relationship created largely by one observation.
- Always plot the data before trusting r.
- Check for outliers and consider whether each is a genuine observation or an error.
- With few points a large r can arise by chance; with five points even r = 0.8 is not strong evidence.
- Restricted ranges, such as sampling only high scorers, shrink r.
A computational shortcut for hand calculation
Subtracting means from every value is clear but slow. An algebraically equivalent version works from raw sums: r = (n × Σxy − Σx × Σy) ÷ √[(n × Σx² − (Σx)²) × (n × Σy² − (Σy)²)]. You need six totals: n, Σx, Σy, Σxy, Σx² and Σy².
Check it on the five-point data. Here Σx = 15, Σy = 15, Σxy = 2 + 2 + 12 + 12 + 25 = 53, Σx² = 55 and Σy² = 55. The numerator is 5 × 53 − 15 × 15 = 265 − 225 = 40. Each bracket in the denominator is 5 × 55 − 225 = 50, so the root of 50 × 50 is 50. The result is 40 ÷ 50 = 0.80, matching the earlier answer exactly.
Spreadsheets compute the same quantity with the CORREL function, which is a quick cross-check for any hand calculation.
Is r bigger than chance would produce?
A sample correlation always has noise. With only five pairs, an r of 0.80 is not statistically convincing: the p-value for that sample is about 0.10. With 30 pairs the same 0.80 would be overwhelming evidence. The test statistic is t = r × √(n − 2) ÷ √(1 − r²), compared with a t distribution on n − 2 degrees of freedom.
- For n = 5, an r of about 0.88 is needed to reach p < 0.05 two-sided.
- For n = 10, about 0.63 is enough.
- For n = 30, about 0.36 is enough.
These thresholds show why small studies with big correlations are fragile, and why a modest r from a very large sample can be statistically significant without being practically useful.
Pearson, Spearman and when to switch
Pearson's r assumes the relationship is roughly linear and that the data are on an interval scale. Spearman's rank correlation applies the same formula to the ranks of the values instead of the values themselves, so it picks up any steadily rising or falling pattern, linear or not, and it is far less moved by outliers.
For example, the data x = 1, 2, 3, 4, 5 and y = 1, 4, 9, 16, 25 follow a perfect curve, y = x². Pearson gives r = 0.98, slightly below 1 because the points are not on a line, while Spearman gives exactly 1 because y rises with every step of x. If your data are ratings or ranks, or you suspect a curve, check both and look at the scatter plot.
Reading the size of r
| |r| | Rough description |
|---|---|
| 0.00 to 0.19 | Very weak or none |
| 0.20 to 0.39 | Weak |
| 0.40 to 0.59 | Moderate |
| 0.60 to 0.79 | Strong |
| 0.80 to 1.00 | Very strong |
What counts as strong depends on the discipline. In physics a correlation of 0.9 may be disappointing, while in social science 0.3 can be meaningful.
Common questions
What is the Pearson correlation coefficient?
It is a number from −1 to +1 measuring the strength and direction of a linear relationship between two variables. +1 is a perfect rising line, −1 a perfect falling line, and 0 means no straight-line association.
How do you calculate Pearson's r?
Subtract each variable's mean, multiply the paired deviations and sum them, then divide by the square root of the product of the two sums of squared deviations. For the five-point example, 8 ÷ 10 = 0.80.
What does r² mean?
It is the share of variation in one variable explained by a straight-line fit to the other. If r = 0.80, then r² = 0.64, so about 64% of the variation is accounted for and 36% is not.
Does correlation prove causation?
No. A strong r can come from a causal link, from a third variable driving both, from coincidence or from outliers. Establishing cause needs a designed experiment or careful causal reasoning beyond the coefficient.
Can the correlation be zero when variables are related?
Yes, if the relationship is not a straight line. Points on a perfect parabola, y = x² over a symmetric range, give r = 0. Always plot the data alongside the coefficient.
Was this guide helpful?
Continue reading
View all blogsWhat a P-Value Is, and What It Is Not
A p-value is the chance of a result at least this extreme if the null hypothesis is true. A two-sided z of 1.96 gives p ≈ 0.050; here is how to read it.
5 min read
Probability Basics: Favourable Over Total Outcomes
Probability is favourable outcomes divided by total equally likely outcomes: rolling a 5 on a fair die is 1/6, or 16.7%. Plus AND, OR and complement rules.
5 min read
Sample Size for a Survey: How Many Responses?
A 95% confidence level and a ±5% margin need about 385 responses for a large population. See the formula and how a smaller population shrinks that.
4 min read




