Linear Regression Calculator

Fit a least-squares line to x and y data. Get the slope, intercept, correlation r, r-squared, and a prediction.

Independently verified for accuracy

Calculator by Toolsloft ↗
Best-fit line
y = 0.6x + 2.2
Correlation r
0.774597
r-squared
0.6

Fit a best-fit straight line to a set of x and y points using least squares. Enter your paired data and get the slope, intercept, correlation, and r-squared, plus an optional prediction at any x. Handy for trend lines in stats and lab work.

How this is calculated

Uses ordinary least squares. The slope is the sum of the cross-deviations of x and y divided by the sum of squared deviations of x, and the intercept places the line through the point of means. The correlation r is the cross-deviation sum divided by the square root of the product of the x and y deviation sums, and r-squared is r times r.

How to use

  1. Enter your x values and the matching y values.
  2. Read the slope, intercept, r, and r-squared.
  3. Enter an x to predict its y on the fitted line.

Examples

  • Best fit: x 1-5, y 2,4,5,4,5 gives y = 0.6x + 2.2
  • Perfect line: y = 2x + 1 has r-squared 1

FAQ

What is least squares?
It is the line that makes the total of the squared vertical distances from the points to the line as small as possible. It is the standard way to fit a straight line to data.
What does r-squared mean?
R-squared is the fraction of the variation in y explained by the line, from 0 to 1. A value near 1 means the points sit close to the line.
Why do I need at least two points?
A line is defined by two points. With one point, or with all x values equal, the slope is not defined.

Embed this calculator

Add this free calculator to your own site. Copy the code and paste it where you want it to appear.