Linear Regression (Least Squares) Calculator

Enter paired x,y data points to find the best-fit line's slope, intercept, and how strongly the two variables correlate.

Slope (m)--
Intercept (b)--
Equation--
Correlation Coefficient (r)--
R-Squared (r²)--
Advertisement
Advertisement

How This Calculator Works

Least-squares linear regression finds the straight line that minimizes the total squared distance between the line and each data point. That line is described by a slope and intercept, and its correlation coefficient (r) tells you how strongly the x and y values move together.

Formula Used

Slope (m) = [n·Σxy − Σx·Σy] ÷ [n·Σx² − (Σx)²]
Intercept (b) = [Σy − m·Σx] ÷ n
r = [n·Σxy − Σx·Σy] ÷ √{[n·Σx² − (Σx)²]·[n·Σy² − (Σy)²]}

How to Use It

Enter your paired data points, one "x,y" pair per line (comma-separated). The calculator computes the best-fit line y = mx + b, along with the correlation coefficient and R-squared value showing how well the line fits your data.

Worked Example

For the sample points (1,2), (2,4.1), (3,5.9), (4,8.2), (5,9.8), the best-fit line comes out to approximately y = 1.98x − 0.03, with a correlation coefficient near 0.9997 — indicating an almost perfectly linear relationship.

Frequently Asked Questions

What does linear regression calculate?

It fits a straight line through data points using the least-squares method to minimize squared distance from each point.

What does the slope represent?

How much the dependent variable (y) is predicted to change per one-unit increase in x.

What does R² tell you?

How well the line fits the data, from 0 to 1 — closer to 1 means a better fit.

Suggest a Calculator

👋 We noticed you might be using an ad blocker. This site is free thanks to ads — consider allowing them here to support us. Thanks!