How to Calculate the Correlation Coefficient (Pearson's r)
How to calculate the correlation coefficient: subtract the mean from every x and every y, multiply each pair of deviations and add the products, then divide that sum by the square root of the sum of squared x deviations times the sum of squared y deviations. The result, Pearson's r, runs from −1 to 1. Its sign gives the direction of a straight-line relationship and its absolute value the strength. Plot the data as well: r only measures straight-line patterns, so r = 0 does not mean there is no relationship.
Last updated · by the simstat.com editorial team · How we write
What the correlation coefficient measures
Pearson’s correlation coefficient r describes how closely paired measurements, such as height and weight or study hours and exam scores, follow a straight line. Illowsky and Dean (2023) call it “a measure of strength and direction of the linear association” and credit it to Karl Pearson. Three facts sum it up:
- Range. r always lies between −1 and 1. At r = 1 or r = −1, “all of the original data points lie on a straight line” (Illowsky and Dean, 2023).
- Direction. A positive r means y tends to rise as x rises; a negative r means y tends to fall. The sign of r is the sign of the slope of the least-squares line.
- Strength. The closer r is to −1 or 1, the more tightly the points hug a line. Near 0 there is no linear pattern, which, as shown below, is not the same as no pattern.
r has no units. You can measure x in centimetres or inches, or y in degrees Celsius or Fahrenheit, and r stays the same, because the formula divides the units away. It is also symmetric: the correlation of x with y equals the correlation of y with x.
The Pearson product moment correlation formula
R’s documentation calls r “Pearson’s product moment correlation coefficient” (R Core Team, 2026, cor.test help page). The recipe is in the formula: multiply the deviations of x and y from their means, add the products, and scale the total so it cannot leave −1 to 1. NIST’s Dataplot reference manual (NIST, 2018) writes the Pearson product moment correlation with three sums:
Here n is the number of pairs, xᵢ and yᵢ are the values of pair i, x̄ and ȳ are the two means, Sxx and Syy are the sums of squared deviations, and Sxy is the sum of cross-products. A pair with both values above their means, or both below, adds a positive product to Sxy; a pair on opposite sides adds a negative one. So Sxy is large and positive when high goes with high, large and negative when high goes with low, and near 0 when the signs cancel out.
Illowsky and Dean (2023) give an equivalent form that needs only the raw totals:
The example below uses the deviation form.
How to calculate the correlation coefficient by hand
The data are the 11 pairs of set I of Anscombe’s quartet, which R ships as datasets::anscombe
(R Core Team, 2026, anscombe help page). The x values are 10, 8, 13, 9, 11, 14, 6, 4, 12, 7, 5; the y values are 8.04, 6.95, 7.58, 8.81, 8.33, 9.96, 7.24, 4.26, 10.84, 4.82, 5.68.
Worked example: Pearson's r for Anscombe's set I
Step 1: the means. The x values add up to 99, so x̄ = 9. The y values add up to 82.51, so ȳ = 7.5009.
Step 2: the deviations. Subtract x̄ from each x and ȳ from each y (columns x − x̄ and y − ȳ).
Step 3: products and squares. Multiply the two deviations in each row, and square each one.
| x | y | x − x̄ | y − ȳ | (x − x̄)(y − ȳ) | (x − x̄)² | (y − ȳ)² |
|---|---|---|---|---|---|---|
| 10 | 8.04 | 1 | 0.539 | 0.539 | 1 | 0.291 |
| 8 | 6.95 | −1 | −0.551 | 0.551 | 1 | 0.304 |
| 13 | 7.58 | 4 | 0.079 | 0.316 | 16 | 0.006 |
| 9 | 8.81 | 0 | 1.309 | 0.000 | 0 | 1.714 |
| 11 | 8.33 | 2 | 0.829 | 1.658 | 4 | 0.687 |
| 14 | 9.96 | 5 | 2.459 | 12.295 | 25 | 6.047 |
| 6 | 7.24 | −3 | −0.261 | 0.783 | 9 | 0.068 |
| 4 | 4.26 | −5 | −3.241 | 16.205 | 25 | 10.503 |
| 12 | 10.84 | 3 | 3.339 | 10.017 | 9 | 11.150 |
| 7 | 4.82 | −2 | −2.681 | 5.362 | 4 | 7.187 |
| 5 | 5.68 | −4 | −1.821 | 7.284 | 16 | 3.316 |
| Sum | 55.010 | 110 | 41.273 |
Step 4: the three sums. Sxy = 55.010, Sxx = 110 and Syy = 41.273. All eleven products are positive or zero: every point lies above both means, below both, or level with x̄.
Step 5: divide. r = 55.010 / √(110 × 41.2727) = 55.010 / √4,540.00 = 55.010 / 67.379 = 0.816.
Check the symmetry and units. Swapping the columns gives r = 0.816. Replacing every x by 100x + 50 (a change of units and origin) also gives r = 0.816.
The table entries are rounded to three decimals; the sums are of the unrounded values, and the rounded entries add up to the same totals here. These data are the default example of our correlation coefficient calculator, so with its default 95% level it shows r = 0.816, r² = 0.667, t = 4.241 on 9 degrees of freedom, p = 0.002, the 95% interval [0.424, 0.951] and the least-squares line ŷ = 3.0001 + 0.5001x.
Which value of r indicates a stronger correlation?
The one further from 0, whatever its sign. Strength is the absolute value |r|; the sign only gives the direction. So r = −0.8 is a stronger correlation than r = 0.6: its points lie closer to a (falling) straight line. Illowsky and Dean (2023) put it this way: “Values of r close to –1 or to +1 indicate a stronger linear relationship between x and y.” NIST’s Dataplot even offers an absolute-value version of its correlation command for screening, “regardless of the direction of the correlation” (NIST, 2018).
What is a strong correlation?
There is no universal cut-off. Several published rules of thumb exist, and they disagree. The R package effectsize
lists them in its interpret_r() documentation (Ben-Shachar et al., 2026); for |r|, two of them are:
| Label | Rule “cohen1988” (attributed to Cohen, 1988) | Rule “evans1996” (attributed to Evans, 1996) |
|---|---|---|
| Very small / very weak | below 0.1 | below 0.2 |
| Small / weak | 0.1 to below 0.3 | 0.2 to below 0.4 |
| Moderate | 0.3 to below 0.5 | 0.4 to below 0.6 |
| Large / strong | 0.5 or more | 0.6 to below 0.8 |
| Very strong | (no category) | 0.8 or more |
Both columns are quoted as effectsize lists them, not from Cohen’s or Evans’s original texts. The same page gives other rules, such as funder2019, its default, which already calls |r| ≥ 0.4 “very large”. By the Cohen column, set I’s r = 0.816 is large; by the Evans column it is very strong.
Use such labels with care. The authors of effectsize write in their vignette on automated interpretation that “these thresholds, as ubiquitous as they may be, remain arbitrary” and that their use “should be discussed on a case-by-case basis depending on the field, hypotheses, prior results, and so on”. Compare your r with earlier results in your field. r is also an effect size: our guide to effect size places it next to Cohen’s d, and the effect size calculator converts between d and r.
r and r²: variance explained
The square of r is the coefficient of determination. Illowsky and Dean (2023) explain that r², as a percentage, “represents the percent of variation in the dependent (predicted) variable y that can be explained by variation in the independent (explanatory) variable x using the regression (best-fit) line”. For set I, r² = 0.667: about 66.7% of the variation in y goes with the line, and 33.3% is scatter around it.
r² shrinks faster than r: r = 0.5 gives r² = 25.0%. It also drops the sign, so report r when the direction matters.
Anscombe’s quartet: always plot first
Anscombe (1973) built four small data sets that, in the words of R’s documentation, “have the same traditional statistical properties (mean, variance, correlation, regression line, etc.), yet are quite different” (R Core Team, 2026, anscombe help page). Their numbers, from the same calculation as above:
| Set | Pearson r | Least-squares line | Spearman’s ρ | x̄ | ȳ |
|---|---|---|---|---|---|
| I | 0.816 | ŷ = 3.00 + 0.500x | 0.818 | 9.0 | 7.50 |
| II | 0.816 | ŷ = 3.00 + 0.500x | 0.691 | 9.0 | 7.50 |
| III | 0.816 | ŷ = 3.00 + 0.500x | 0.991 | 9.0 | 7.50 |
| IV | 0.817 | ŷ = 3.00 + 0.500x | 0.500 | 9.0 | 7.50 |
The four plots, drawn with the least-squares line on each set’s own axes, tell four different stories that r cannot. Only set I fits the picture that r = 0.816 suggests. Spearman’s ρ, which R’s documentation describes as computing “cor(R(x), R(y))”, the correlation of the ranks, already hints that something differs (R Core Team, 2026, cor help page). Among the questions a scatter plot answers, the NIST/SEMATECH e-Handbook lists “Are variables X and Y linearly related?” and “Are there outliers?”. Illowsky and Dean (2023) give the rule in one line: “it is always important to plot a scatter diagram first.”
When the correlation is zero
An r of 0 means no linear relationship. Illowsky and Dean (2023) warn that data “that exhibit a curved or horizontal pattern may have a correlation of 0”, right after “It is important to view the scatterplot”.
No correlation examples
Take y = x² for x = −3, −2, −1, 0, 1, 2, 3, so y = 9, 4, 1, 0, 1, 4, 9. Every y is fixed exactly by its x, yet r = 0 exactly, and the least-squares line is flat (slope 0). The products in Sxy cancel: each point on the left has a mirror image on the right with the opposite sign of x − x̄.
Keep the same curve but use x = 0, 1, 2, 3, 4, 5, 6, and r = 0.961: in the top category of every rule above, though the curve is not a line either. The same relationship gives r = 0 or r = 0.961 depending on which x values were observed. When the correlation is zero, look at the plot before concluding that the variables are unrelated.
Outliers and restricted range
One point can move r a long way. Anscombe’s set III lies on a straight line, to the two decimals given, except for its third point; with that
point r = 0.816, without it r = 0.999997. In set IV every x is 8 except one, which
is 19. That single point has leverage 1: it alone fixes the slope, and r = 0.817 rests on
it. Our calculator warns about both: it flags the set III point, whose studentised (deleted) residual, R’s
rstudent(), is 1,203.54, far past its ±3 cut-off, and it names the set IV point as the one that
alone fixes the slope. Leverage, from 0 to 1, measures how far a point’s x lies from the others. Look at the plot too.
The range of the data matters too. Price et al. (2017) describe restriction of range, when “one or both of the variables have a limited range in the sample relative to the population”. In their hypothetical example a correlation of −.77 between age and enjoyment of hip hop music would fall to 0 if only 18- to 24-year-olds were sampled. They advise designing studies to avoid it and, because it cannot always be avoided, “to interpret Pearson’s r in light of it”.
How to report a correlation
Give the coefficient with its degrees of freedom (n − 2), a confidence interval and the p-value. For set I:
Across the 11 pairs, x and y were positively correlated, r(9) = 0.82, 95% CI [0.42, 0.95], p = 0.002 (Pearson’s r, Fisher z interval).
The p-value tests whether the population correlation is 0, with t = r√(n − 2)/√(1 − r²) on n − 2 degrees of freedom.
R’s documentation says this statistic follows a t distribution “if the samples follow independent normal
distributions”, and adds: “If there are at least 4 complete pairs of observation, an asymptotic confidence
interval is given based on Fisher’s Z transform” (R Core Team, 2026, cor.test help page). Our calculator uses the same methods, so cor.test(anscombe$x1, anscombe$y1) in R
returns the same values. Our guide to
interpreting confidence intervals explains how to read the
interval.
Also report:
- n, and how missing or excluded pairs were handled;
- the scatter plot, or a note that you checked it for curvature and outliers;
- any removed point, with r with and without it;
- the method, if you used Spearman’s ρ instead (for set I, ρ = 0.818).
Common mistakes
Reading r = 0 as “no relationship”. It means no straight-line relationship. The parabola above has r = 0 and a perfect dependence.
Judging strength by the sign. A negative r is not weaker than a positive one. Compare |r|: −0.8 beats 0.6.
Treating r as the slope. r is unit-free; the slope is not. Set I has slope 0.5001 and r = 0.816. Rescale x and the slope changes, while r stays 0.816.
Reading correlation as cause. Illowsky and Dean (2023) put it plainly: “Strong correlation does not suggest that x causes y or y causes x.” The NIST/SEMATECH e-Handbook adds that “association does NOT imply causality”: a scatter plot “can never ‘prove’ cause and effect.”
Applying strength labels mechanically. “Large” under one rule is “moderate” under another: r = 0.55 is large by cohen1988 and moderate by evans1996. Report the value and its interval.
Where to go next
Why a strong r is not proof of cause is the subject of correlation vs causation; the statistics hub lists more. To compute r, ρ and the interval for your own data, use the correlation coefficient calculator; to compare r with other effect sizes, read the effect size guide.
References
- Illowsky, B. & Dean, S. (2023). Introductory Statistics 2e, Section 12.3: The Regression Equation. OpenStax, Rice University.
- NIST/SEMATECH (2012). e-Handbook of Statistical Methods, Section 1.3.3.26: Scatter Plot. National Institute of Standards and Technology.
- NIST (2018). Dataplot Reference Manual: CORRELATION. National Institute of Standards and Technology.
- Anscombe, F. J. (1973). Graphs in Statistical Analysis. The American Statistician, 27(1), 17–21.
- R Core Team (2026). anscombe: Anscombe's Quartet of 'Identical' Simple Linear Regressions (datasets package documentation). R Foundation for Statistical Computing.
- R Core Team (2026). cor.test: Test for Association/Correlation Between Paired Samples (stats package documentation; cor is at stat.ethz.ch/R-manual/R-devel/library/stats/html/cor.html). R Foundation for Statistical Computing.
- Ben-Shachar, M. S., Makowski, D., Lüdecke, D. et al. (2026). effectsize reference manual: interpret_r, Interpret Correlation Coefficient. easystats.
- Ben-Shachar, M. S., Makowski, D., Lüdecke, D. et al. (2026). Automated Interpretation of Indices of Effect Size (effectsize package vignette). easystats.
- Price, P. C., Jhangiani, R. S., Chiang, I-C. A. & Leighton, D. C. (2017). Research Methods in Psychology, 2nd American Edition (Chapter 12). eCampusOntario Open Library (CC BY-NC-SA 4.0).
Try it
- Correlation coefficient calculator: Pearson and Spearman: Pearson's r with a Fisher z interval and t test, Spearman's ρ, r², the least-squares line and a scatter plot that flags outliers.
- Effect size calculator: Cohen's d, Hedges' g: Cohen's d, Hedges' g and Glass's Δ with noncentral t intervals, d to r conversion, and partial η² from F.
Related reading
- Correlation vs Causation: Why Correlation Does Not Imply Causation
- Effect Size: Definition, Cohen's d and How to Interpret It
- How to Find Class Boundaries, Class Limits and Midpoints
- How to Find Class Width: Formula, Rounding and Decimals
- How to Find IQR (Interquartile Range): Formula and Examples
- More on statistics