On this page
Before you start
This page is easier if you are comfortable with:
What this topic covers
The line of best fit minimises the squared vertical distances (linear regression line , line of best fit). The strength of the relationship is measured by the product moment correlation coefficient, which is always between −1 and 1.
Each part of this topic has its own page with the formula, worked examples and a solver: Linear regression line, Product moment correlation coefficient, Line of best fit.
Closely related topics: Averages and spread, Histograms and box plots , Straight lines and coordinates, Probability distributions .
What is it used for? Correlation measures how closely two variables follow a straight line, and regression gives the equation of that line so you can make predictions.
Predicting one quantity from another, such as sales from advertising. Checking whether two measurements are related. Drawing a line of best fit through a scatter graph.
How to solve it
Work out the means of x and y. Sxy = Σ(x - x̄)(y - ȳ) and Sxx = Σ(x - x̄)². Gradient b = Sxy ÷ Sxx. Intercept a = ȳ - b x̄. r = Sxy ÷ √(Sxx × Syy). Only predict inside the range of the data (interpolation).
Worked examples
The examples marked with a button were worked out by the solver on this page. You can try each one yourself.
Example 1: scatter x: 1, 2, 3, 4, 5 y: 2, 4, 5, 4, 5 Worked out by the solver on this page. Press the button to try it yourself.
Try this in the solver: scatter x: 1, 2, 3, 4, 5 y: 2, 4, 5, 4, 5
Scatter graph and regression Answer checked
Answer
y = 2.2 + 0.6 x y = 2.2 + 0.6x y = 2.2 + 0.6 x r = 0.77459667
Scatter graph mean 0 1 2 3 4 5 6 2 3 4 5 6 Scatter graph x y Graph with x from -0.38 to 6.38 and y from 1.466 to 6.094. Shows data (5); point mean at (3, 4). Means
x ˉ = 3 , y ˉ = 4
Sums of squares and products
S xx = 10 , S y y = 6 , S x y = 6
Gradient and intercept
The line passes through the mean point ( x ˉ , y ˉ ) .
b = S xx S x y = 0.6 , a = y ˉ − b x ˉ = 2.2
Product moment correlation coefficient
This is a moderate positive correlation.
r = S xx S y y S x y = 0.77459667 Check: the residuals cancel out and the slope matches r × (spread of y ÷ spread of x)
∑ ( y − y ^ ) = 0 ≈ 0 ✓
Example 2: line of best fit (1,3), (2,5), (3,7), (4,9) Worked out by the solver on this page. Press the button to try it yourself.
Try this in the solver: line of best fit (1,3), (2,5), (3,7), (4,9)
Scatter graph and regression Answer checked
Answer
y = 1 + 2 x y = 1 + 2x y = 1 + 2 x r = 1
Scatter graph mean 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 2 4 6 8 10 Scatter graph x y Graph with x from -0.035 to 5.035 and y from 0.93 to 11.07. Shows data (4); point mean at (2.5, 6). Means
x ˉ = 2.5 , y ˉ = 6
Sums of squares and products
S xx = 5 , S y y = 20 , S x y = 10
Gradient and intercept
The line passes through the mean point ( x ˉ , y ˉ ) .
b = S xx S x y = 2 , a = y ˉ − b x ˉ = 1
Product moment correlation coefficient
This is a strong positive correlation.
Check: the residuals cancel out and the slope matches r × (spread of y ÷ spread of x)
∑ ( y − y ^ ) = 0 ≈ 0 ✓
Example 3: correlation x: 1,2,3,4 y: 8,6,4,1 Worked out by the solver on this page. Press the button to try it yourself.
Try this in the solver: correlation x: 1,2,3,4 y: 8,6,4,1
Scatter graph and regression Answer checked
Answer
y = 10.5 − 2.3 x y = 10.5 - 2.3x y = 10.5 − 2.3 x r = − 0.99437671
Scatter graph mean 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 0 2 4 6 8 10 Scatter graph x y Graph with x from -0.035 to 5.035 and y from -1.0805 to 10.5805. Shows data (4); point mean at (2.5, 4.75). Means
x ˉ = 2.5 , y ˉ = 4.75
Sums of squares and products
S xx = 5 , S y y = 26.75 , S x y = − 11.5
Gradient and intercept
The line passes through the mean point ( x ˉ , y ˉ ) .
b = S xx S x y = − 2.3 , a = y ˉ − b x ˉ = 10.5
Product moment correlation coefficient
This is a strong negative correlation.
r = S xx S y y S x y = − 0.99437671 Check: the residuals cancel out and the slope matches r × (spread of y ÷ spread of x)
∑ ( y − y ^ ) = 0 ≈ 0 ✓
Special cases
A few situations come up again and again. Knowing them saves time and helps you spot answers that cannot be right.
Positive correlation r near +1
y rises as x rises.
No correlation r near 0
No linear pattern.
Gradient Sxy/Sxx = 30/25 = 1.2
Slope of the regression line.
Intercept ȳ − b x̄
The line passes through the means.
Word problems
Plot the data, calculate r for the strength, and use y = a + bx with b = Sxy/Sxx to predict.
Gradient Sxy = 30, Sxx = 25: find b.
b 30/25 Check: 1.2 ✓ 1.2
Intercept x̄ = 3, ȳ = 4, b = 1.2: find a.
a = ȳ − b x̄ 4 − 3.6 Check: the line passes through (3, 4) ✓ 0.4
Correlation Higher Sxy = 30, Sxx = 25, Syy = 40: find r.
r 30/√1000 Check: strong positive ✓ 0.9487
Prediction Higher Predict y at x = 5 with y = 0.4 + 1.2x.
Substitute 0.4 + 6 Check: 6.4 ✓ 6.4
Common mistakes
Correlation means causation x causes y ✗
only association ✓
A third factor may drive both.
Extrapolating far beyond the data predict at x = 100 ✗
be careful outside the range ✓
Unreliable.
r outside [−1, 1] r = 1.2 ✗
check the arithmetic ✓
The coefficient is bounded.
Swapping x and y regress x on y ✗
y on x for predicting y ✓
The lines differ.
Exam tips
r between −1 and 1.
b = Sxy/Sxx.
Line through (x̄, ȳ).
Interpolate, do not extrapolate.
Correlation ≠ causation.
Practice questions
Try each one on paper, then open the answer. Use the solver above to see the full working.
1. b: Sxy = 18, Sxx = 12 Foundation 1.5
2. a: ȳ = 10, x̄ = 4, b = 2 Foundation 2
3. y at x = 6 for y = 2 + 3x Foundation 20
4. r: Sxy = 12, Sxx = 9, Syy = 16 Higher 1
5. Mean of y: 2, 4, 5, 4, 5 Higher 4
6. y at x = 10 for y = 1 + 0.5x Higher 6
Practice generator Unlimited fresh questions with instant marking. Choose a level, work it out on paper, then type your answer.
Foundation Higher Mixed New question
Solve: …
The practice generator needs JavaScript.
Key terms
Correlation Linear association. Regression line y = a + bx. Gradient Change in y per unit x. Residual Observed minus predicted. Interpolation Prediction inside the data range. Extrapolation Prediction outside the range.
Frequently asked questions
What does the correlation coefficient measure? The strength and direction of a linear relationship.
How do I find the regression line? b = Sxy/Sxx and a = ȳ − b x̄.
Does correlation prove cause? No.
Which page covers the regression line? linear regression line.
Which page covers r? product moment correlation coefficient.
Which page covers a line of best fit? line of best fit.