CalcArcade.

Linear Regression Calculator

Enter your x values and your y values, in the same order, and optionally an x to predict from. You get the equation of the best fit line, the correlation and how much of the variation the line explains.

Your numbers

Result

How we calculate it

The best fit line is found by least squares. With the means x̄ and ȳ, the slope is the sum of (x − x̄)(y − ȳ) divided by the sum of (x − x̄)², and the intercept is ȳ − slope × x̄. The correlation r is the sum of (x − x̄)(y − ȳ) divided by the square root of the product of the two sums of squares, and R squared is r².

For the points (1, 2), (2, 3), (3, 5), (4, 4) and (5, 6), the slope is 0.9, the intercept is 1.3, r is 0.9 and R squared is 0.81. The line is y = 0.9x + 1.3, so at x = 6 the predicted y is 6.7.

Assumptions and limits

  • You need at least two points, and the x values cannot all be the same.
  • If every y value is the same, the line is flat and the correlation is not defined.
  • A strong correlation does not show that one thing causes the other, and predictions far outside your x range are unreliable.

Frequently asked questions

What does R squared mean?

R squared is the share of the variation in y that the line explains. An R squared of 0.81 means about 81% of the variation in y is accounted for by the straight line on x.

What does the correlation r tell me?

It runs from −1 to 1. Close to 1 means y rises steadily with x, close to −1 means y falls as x rises, and close to 0 means there is no straight line pattern.

How many points do I need?

Two points always fit a line exactly, but they tell you little. More points give a more reliable line, and you should plot your data to check that a straight line suits it.

Related calculators

Worked example (a fixed example using the starting numbers, it does not change as you type)

Inputs: x values (separate with commas, spaces or new lines) = 1, 2, 3, 4, 5; y values (same number, same order) = 2, 3, 5, 4, 6; x to predict y for = 6.

  • Slope 0.9
  • Intercept 1.3
  • Equation y = 0.9x + 1.3
  • Correlation (r) 0.9
  • R squared 0.81
  • Number of points 5
  • Predicted y 6.7

Embed this calculator

Add this calculator to your own page. Paste the code where you want it. The small link keeps credit to the source.

More statistics calculators

Last reviewed: . Formulas and assumptions are described on our methodology page. For information only; not professional advice.