Correlation Coefficient Calculator

Paste your x values and y values below and get Pearson's r, r squared, and the best-fit line, with every step of the working shown from your own numbers.

Put this calculator on your website for free

Copy one snippet and give your visitors a working Correlation Coefficient Calculator.

How the correlation coefficient calculator works

Pearson's correlation coefficient answers one question: when x moves, how reliably does y move with it, in a straight line? The recipe has four steps, and the calculator runs them on your own numbers and shows each one. First it finds the mean of your x values and the mean of your y values. Then, for every pair, it measures how far x sits from its mean and how far y sits from its mean, and multiplies the two deviations together: a pair where both are above their means (or both below) gives a positive product, a pair where they disagree gives a negative one. Adding those products up gives the covariance numerator, the raw measure of moving-together. Finally it divides by the square root of the two sums of squared deviations, which is the largest that numerator could possibly be, so the answer always lands between -1 (a perfect downhill line) and +1 (a perfect uphill line), with 0 meaning no straight-line pattern at all.

The calculator also fits the least squares line through your points and lists each residual, the observed y minus the y the line predicted, which is the part of y the line did not explain. This page and the least squares regression calculator are deliberate siblings: that page predicts (feed it an x, it hands back a y), while this page measures how much a straight line deserves your trust in the first place. The two run the same arithmetic underneath, so they can never disagree.

The formula

r = Σ(x − x̄)(y − ȳ) ⁄ √(Σ(x − x̄)² · Σ(y − ȳ)²)

Here x̄ and ȳ are the means of the two lists and the sums run over all n pairs. The numerator is the co-variation: how much x and y stray from their means in the same direction at the same time. The denominator is the same quantity's ceiling, what the numerator would be if the pairing were perfect, which is why r is a pure number with no units: measure height in inches or centimeters and r does not change, because scaling a variable stretches the numerator and the denominator by the same factor. Squaring r gives r2, the share of the variation in y that the straight-line relationship accounts for.

Worked example

Five students report hours studied x = 1, 2, 3, 4, 5 and quiz scores y = 2, 4, 5, 4, 6. The means are x̄ = 3 and ȳ = 4.2. The deviation products are (−2)(−2.2) + (−1)(−0.2) + (0)(0.8) + (1)(−0.2) + (2)(1.8) = 4.4 + 0.2 + 0 − 0.2 + 3.6 = 8. The squared deviations sum to Σ(x − x̄)² = 4 + 1 + 0 + 1 + 4 = 10 and Σ(y − ȳ)² = 4.84 + 0.04 + 0.64 + 0.04 + 3.24 = 8.8. So r = 8 ⁄ √(10 × 8.8) = 8 ⁄ 9.3808 ≈ 0.8528, a strong positive correlation, and r20.7273: hours studied account for about 72.7% of the variation in these scores, and the other 27.3% is everything else about a quiz and a life. The fitted line is ŷ = 0.8x + 1.8, and its residuals (−0.6, 0.6, 0.8, −1, 0.2) sum to exactly zero. Paste those two lists above and you get every one of these numbers.

What counts as strong (and who gets to say)

The usual ladder reads: 0.9 and above very strong, 0.7 to 0.9 strong, 0.4 to 0.7 moderate, 0.2 to 0.4 weak, below 0.2 little to none, with the same rungs on the negative side. Those bands are conventions, not verdicts, and they vary by field more than most textbooks admit. In psychology, where every measurement passes through a human being, an r of 0.3 can be a solid, publishable effect. In a physics lab, where the relationship between voltage and current is supposed to be a law, that same 0.3 usually means a loose cable. So when this page calls your r "moderate," read it as "moderate by the common convention," and then ask the better question: is it strong for data like yours? A useful companion habit: square it. An r of 0.5 sounds respectable and explains 25% of the variation, which keeps everyone appropriately humble. And if you need to know whether an r this size could plausibly arise by chance at your sample size, that is a significance question, which is the p-value calculator's department, not this page's.

Correlation is not causation (here is what else it could be)

A genuine, well-measured correlation between x and y has at least four explanations, and r cannot tell them apart. Maybe x really does cause y. Maybe y causes x, which is reverse causation: cities with more police have more recorded crime, mostly because crime brings police, not the other way round. Maybe a lurking third variable drives both: ice cream sales correlate beautifully with drowning deaths, and the cause of both is summer, when people eat ice cream and swim. Or maybe it is chance, a pattern in this sample that a larger one would wash out, which is why small n deserves extra suspicion. None of this makes correlation useless: it is how relationships get noticed in the first place. It just means the coefficient is the start of the investigation, not the conclusion. Sorting the four explanations apart takes controlled experiments or careful causal reasoning, and no value of r, however beautiful, can do that work by itself.

The Anscombe warning: four datasets, one r

In 1973 the statistician Francis Anscombe built four small datasets that have been keeping analysts honest ever since. All four share nearly identical summary statistics: the correlation is about 0.816 in every one, and the fitted line is essentially ŷ = 0.5x + 3 in every one. Plotted, they look nothing alike: one is an ordinary noisy trend, one is a clean curve that a straight line insults, one is a tight line with a single outlier dragging the fit, and one is a vertical stack of points with one far-off pair inventing the whole relationship. Same r, four completely different stories. The lesson generalizes: r measures linear association only. A perfect curve can score near zero (x = −2, −1, 0, 1, 2 against y = 4, 1, 0, 1, 4 is a flawless parabola with r exactly 0, because the upslope and downslope cancel), and one outlier can manufacture or destroy an impressive coefficient. So always look at the shape of your data, not just the number: the residuals table this page prints is a plot you can read without graph paper, and a standard deviation check on each list will flag the stray value that is quietly running the show.

Frequently asked questions

How do you calculate the correlation coefficient?

Four steps. Find the mean of the x values and the mean of the y values. For each pair, measure how far x sits from its mean and how far y sits from its mean, and multiply those two deviations together. Add all the products up: that sum is the numerator. Divide it by the square root of (the sum of squared x deviations times the sum of squared y deviations), which is the largest the numerator could possibly be. The answer always lands between -1 and 1. This page runs those exact steps on your own numbers and shows each one.

What is a strong correlation?

The usual convention calls 0.9 and above very strong, 0.7 to 0.9 strong, 0.4 to 0.7 moderate, and 0.2 to 0.4 weak, with the same words on the negative side. Treat those as habits, not laws: they vary by field. An r of 0.3 can be a publishable finding in psychology, where humans add noise to everything, and a sign of broken equipment in a physics lab, where relationships are expected to be nearly exact. The honest question is not whether r clears a threshold but whether it is strong for data like yours.

What does r squared mean?

Square r and you get the share of the variation in y that the straight-line relationship accounts for. An r of 0.80 gives r squared of 0.64: the line explains 64% of what makes y move, and the other 36% is measurement noise, other variables, or curvature the line cannot see. It is a useful humility check, because an impressive-sounding r of 0.5 explains only 25% of the story.

Can correlation prove causation?

No, and it helps to know exactly why not. A real correlation between x and y has at least four explanations: x causes y, y causes x (reverse causation), some third variable drives both, or the pattern is chance that a larger sample would wash out. The classic example is ice cream sales and drowning deaths, which correlate strongly because summer drives both. Telling the explanations apart takes controlled experiments or careful causal inference, not a bigger r.

What is a residual?

A residual is one point's leftover: the observed y minus the y the fitted line predicted for that x. It is the part of y the line did not explain. Positive residuals sit above the line, negative ones below, and for a least squares fit they always sum to exactly zero, which this calculator renders as a self-check step. Big residuals are where to look first for typos, outliers, and curvature.

Why is my r low when the pattern is obvious?

Because r measures straight-line association only. A perfect curve can score near zero: paste x = -2, -1, 0, 1, 2 with y = 4, 1, 0, 1, 4 (a flawless parabola) and r comes back exactly 0, since the upslope and downslope cancel. If your eye sees a clear pattern and r disagrees, believe your eye first and look at the shape: the relationship may be real but curved, and a straight line is simply the wrong ruler for it.

What happens with only two points?

You always get r = 1 or r = -1, no matter what you measured, because a straight line passes exactly through any two points. The number is real but empty: it tells you that you have two points, nothing about the relationship between the variables. This calculator computes it and then says so plainly. With three points r starts to carry information, and the more pairs you add, the more one number deserves your trust.

Related calculators