Linear Regression Calculator

Enter x and y values to find the line of best fit, its slope and intercept, the correlation r and R², with a scatter plot and step-by-step working.

How is your data laid out?

Commas, spaces or new lines.

5 numbers read

In the same order as x.

5 numbers read

Optional. Uses the line of best fit.

Line of best fit for 5 points

Regression equation

ŷ = 0.6x + 2.2

least-squares line, ŷ = bx + a

Slope (b)
0.6
y-intercept (a)
2.2
Correlation (r)
0.7746
strong positive
R²
0.6
60% of the variation in y
Predicted y at x = 6
5.8
Standard error of estimate
0.8944

Results are rounded to 4 decimal places. Predictions outside the range of your x values are extrapolation and may not hold.

2.122.913.74.485.271.142.0733.934.86xy
Your points and the line of best fit, ŷ = 0.6x + 2.2.

Step-by-step working

  1. Find the means of x and y.x̄ = 3, ȳ = 4 (n = 5)
  2. For each point, work out (x − x̄), (y − ȳ), their product and their squares, then add each column (see the table below).Sxy = Σ(x − x̄)(y − ȳ) = 6Sxx = Σ(x − x̄)² = 10, Syy = Σ(y − ȳ)² = 6
  3. Slope: divide Sxy by Sxx.b = 6 ÷ 10 = 0.6
  4. Intercept: the line passes through the point of means (x̄, ȳ), so a = ȳ − b·x̄.a = 4 − 0.6 × 3 = 2.2
  5. Correlation coefficient: r = Sxy ÷ √(Sxx · Syy). Squaring it gives R², the share of the variation in y the line explains.r = 6 ÷ √(10 × 6) = 0.7746; R² = 0.6

Working table

xyx − x̄y − ȳ(x − x̄)(y − ȳ)(x − x̄)²(y − ȳ)²
12-2-2444
24-10010
3501001
4410010
5521241
Sum6106

Regression formulas

Slope

b = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)² = Sxy ÷ Sxx

Intercept

a = ȳ − b·x̄

Line of best fit

ŷ = bx + a

Correlation coefficient

r = Sxy ÷ √(Sxx · Syy)

Worked example

Points: (1, 2), (2, 4), (3, 5), (4, 4), (5, 5).

  1. Means: x̄ = 3, ȳ = 4.
  2. Sxy = (-2)(-2) + (-1)(0) + (0)(1) + (1)(0) + (2)(1) = 6.
  3. Sxx = (-2)² + (-1)² + (0)² + (1)² + (2)² = 10.
  4. Slope b = 6 ÷ 10 = 0.6.
  5. Intercept a = 4 − 0.6 × 3 = 2.2.
  6. The line is ŷ = 0.6x + 2.2, with r = 0.7746 and R² = 0.6: the line explains 60% of the variation in y.

Before you trust the line

  • Look at the scatter plot. If the points curve, a straight line is the wrong model even when r looks high.
  • Check for outliers. One point far from the rest can swing the slope a long way.
  • Keep predictions inside the range of x you measured.

To summarize one variable at a time, use the mean, median and mode calculator and the standard deviation calculator.

Frequently Asked Questions

More statistics calculators