Skip to main content

Correlation and regression calculator

Paste the x values and the y values in the same order. You get Pearson's r, the least-squares regression line, Spearman's rank correlation and a scatter graph with the line.

r = 0.994;   y = 3.57x + 23.3
Pearson's r
0.994
r²
0.988
Gradient (y on x)
3.57
Intercept (y on x)
23.3
Spearman's rs
1.00
Graph loads here
Show the working

n = 7,   x̄ = 6.71,   ȳ = 47.3

Sxx = Σ(x − x̄)² = 63.4,   Syy = 819,   Sxy = Σ(x − x̄)(y − ȳ) = 227

r = Sxy ÷ √(SxxSyy) = 0.994,   r² = 0.988

Regression line of y on x: gradient = Sxy ÷ Sxx = 3.57, intercept = ȳ − gradient × x̄ = 23.3, so y = 3.57x + 23.3

Line of x on y (to estimate x from y): x = 0.276y − 6.36

Spearman's rank: rank each variable, then find r of the ranks: rs = 1.00

Answers are rounded to 3 significant figures. A Level questions usually say how accurate to be: follow the question.

How to do it by hand

  1. Work out the means x̄ and ȳ and the sums Sxx = Σ(x − x̄)², Syy = Σ(y − ȳ)² and Sxy = Σ(x − x̄)(y − ȳ).
  2. Pearson's r = Sxy ÷ √(Sxx Syy). It is between −1 and 1.
  3. The regression line of y on x has gradient Sxy ÷ Sxx and passes through (x̄, ȳ).
  4. Spearman's rank: rank each variable, then find r for the ranks (with no ties, rₛ = 1 − 6Σd² ÷ [n(n² − 1)]).

Worked example

Seven students recorded hours of revision x and their test score y: (1, 52), (3, 58), (4, 61), (6, 70), (7, 69), (9, 80), (10, 83). Find r and the regression line of y on x.

Solution

n = 7,   x̄ = 5.71,   ȳ = 67.6

Sxx = Σ(x − x̄)² = 63.4,   Syy = 778,   Sxy = Σ(x − x̄)(y − ȳ) = 220

r = Sxy ÷ √(SxxSyy) = 0.991,   r² = 0.982

Regression line of y on x: gradient = Sxy ÷ Sxx = 3.47, intercept = ȳ − gradient × x̄ = 47.7, so y = 3.47x + 47.7

Line of x on y (to estimate x from y): x = 0.283y − 13.4

Spearman's rank: rank each variable, then find r of the ranks: rs = 0.964

Answer: r = 0.991;   y = 3.47x + 47.7

Every number in this example is worked out by the same code as the tool above, and the code is tested against independent results from Python's SciPy library.

Where you need it

The product-moment correlation coefficient (PMCC) and its hypothesis test in A Level statistics; Spearman's rank in some Further Statistics options and IAL S3. Both come from the same regression screen.

Practise it: Hypothesis testing · Statistical sampling and data.

On your calculator

In the exam you use your own calculator, so practise it too. Our guides give the exact keystrokes for the Casio fx-CG50, TI-Nspire CX II, TI-84 Plus CE, Casio fx-991EX ClassWiz and Casio fx-991CW ClassWiz, with a worked example to check against:

Common mistakes

Questions students ask

What counts as a strong correlation?

As a rough guide, |r| above about 0.7 is strong and below about 0.3 weak, but it also depends on how many points you have. Always look at the scatter graph as well.

What is the difference between Pearson's and Spearman's correlation?

Pearson's r measures how close the points are to a straight line. Spearman's rₛ measures how consistently y goes up (or down) as x goes up, straight or curved, using the ranks.

What does r² mean?

The proportion of the variation in y that is explained by the straight-line relationship with x. r = 0.9 gives r² = 0.81, about 81%.

More maths tools