Linear Regression Calculator
Find the best-fit line and R² for a set of x/y data points.
Assumptions used in this calculation
- Ordinary least squares: Fits the line that minimizes the sum of squared vertical distances from each point (OLS), which weights outliers heavily since errors are squared.
About this calculator
Fitting a straight line to scattered data points by eye is subjective, and the actual least-squares calculation, the slope and intercept formulas involve several running sums across every data point, is tedious enough that hand computation invites errors well before you get to judging how good the fit even is. This calculator takes paired x and y values and computes the ordinary least-squares best-fit line using slope = (nΣxy − ΣxΣy) ÷ (nΣx² − (Σx)²) and intercept = (Σy − slope·Σx) ÷ n, the line that minimizes the sum of squared vertical distances from each point. It also reports R², the coefficient of determination, from 0 (no linear relationship) to 1 (a perfect line), showing how much of y's variance the line actually explains. Because squaring the errors weights outliers heavily, a single far-off point can noticeably pull the fitted line. That replaces the by-hand summation and squaring across every data point with an instant, objective best-fit line and fit quality measure.
Worked example
5 data points
Result: y = 0.6x + 2.2, R² = 0.6
Was this helpful?

