StatGardenREF. DESK
Calculators/Statistics/Correlation & linear regression
Statistics

Correlation & linear regression calculator

Pearson r and the line of best fit for paired data.

What this calculator does

Correlation measures how closely two variables move together, on a scale from −1 to +1. A value near zero means no linear relationship; values near either extreme mean the points fall close to a straight line. Linear regression then fits that line, giving an equation you can use to predict one variable from the other.

The most important caveat is the oldest one: correlation is not causation. Two variables can move together because one causes the other, because both are driven by something else, or by pure coincidence in a small sample. The arithmetic cannot distinguish these cases, and nothing in the output should be read as if it could.

The formula

Formular = Σ(x−x̄)(y−ȳ) / √(Σ(x−x̄)²Σ(y−ȳ)²); slope b = r·sy/sx; intercept a = ȳ − b·x̄

Pearson’s r divides the covariance of the two variables by the product of their standard deviations, which normalises it onto the −1 to +1 scale. The regression slope is r scaled by the ratio of the standard deviations, and the intercept is fixed by requiring the line to pass through the mean of both variables.

TermMeaning
rPearson correlation coefficient, from −1 to +1.
The proportion of variance in y explained by x.
SlopeHow much y changes per unit of x.
InterceptThe value of y when x is zero.
CovarianceHow the two vary together, in the original units.

The inputs explained

FieldWhat to enter
X valuesThe x values, separated by commas.
Y valuesThe y values, in the same order. Both lists must have at least two matching pairs.

When to use it

Testing whether two measures relate

Study hours against exam scores, temperature against sales, advertising spend against revenue. The correlation quantifies the strength of the linear association.

Making a prediction

The line of best fit gives an equation. Substituting a new x produces a predicted y, though predictions far outside the range of your data are unreliable.

Understanding how much is explained

R² is the more interpretable figure. A correlation of 0.7 sounds strong until you note that R² is 0.49: under half the variation is accounted for.

Checking for a non-linear relationship

Pearson’s r only detects linear association. A perfect parabolic relationship can produce a correlation near zero, which is why plotting the data matters as much as calculating the coefficient.

Worked examples

Every figure in the tables below is produced by this page’s own calculator at build time, so the numbers and the tool always agree. Select any row to load that scenario.

Correlation across different data patterns

The x values are 1 through 8 in every row; only the y values change.

Same x values, different y
Y valuesCorrelation rR² (variance explained)Strength
2, 4, 6, 8, 10, 12, 14, 161.000100.0%Strong
2.1, 4.3, 6.2, 7.9, 10.4, 12…0.999599.9%Strong
3, 7, 5, 9, 8, 12, 11, 150.931486.8%Strong
16, 14, 12, 10, 8, 6, 4, 2-1.000100.0%Strong
5, 9, 12, 14, 14, 12, 9, 500.000%Negligible
8, 3, 12, 5, 15, 2, 9, 70.01990.039%Negligible
The fifth row is a near-perfect inverted parabola, yet its correlation is close to zero: a clear demonstration that r only measures linear association. The fourth row is a perfect negative relationship at r = −1.

How one outlier distorts the result

A well-behaved data set with a single point moved progressively further out of line.

Adding an extreme point
Y valuesCorrelation rR² (variance explained)Line of best fit
2, 4, 6, 8, 10, 121.000100.0%y = 2.000x + 0
2, 4, 6, 8, 10, 200.922085.0%y = 3.143x − 2.667
2, 4, 6, 8, 10, 400.792462.8%y = 6.000x − 9.333
2, 4, 6, 8, 10, 1000.708450.2%y = 14.571x − 29.333
The correlation stays high throughout even as the slope becomes wildly distorted. A strong r does not mean the line is a sensible description of the data.

Questions

What is a strong correlation?

Conventionally, above 0.8 in absolute value is strong, 0.5 to 0.8 moderate, and below 0.3 negligible. But context matters enormously: a correlation of 0.4 can be substantial in social science and disappointing in physics.

Does correlation prove causation?

No. Two variables may correlate because one causes the other, because a third factor drives both, or by coincidence. Establishing causation requires experimental design or careful causal inference, not a coefficient.

What does R squared mean?

The proportion of variance in y explained by x. An R² of 0.64 means 64 per cent of the variation is accounted for by the linear relationship, and 36 per cent is not.

Can correlation be zero when a relationship exists?

Yes. Pearson’s r measures linear association only. A symmetric curved relationship can give r near zero despite being perfectly deterministic: which is why plotting the data is essential.

How many data points do I need?

At least two for the arithmetic, but correlations from small samples are unstable and can be large by chance. Meaningful conclusions generally need considerably more, and the number depends on the effect size you are hoping to detect.

For summarising each variable separately, see descriptive statistics. For precision of an estimate, use confidence intervals.