calculator least squares regression line

Least Squares Regression Line Calculator

Enter one data point per line in the form x, y (comma or space separated). The calculator finds the best-fit line: ŷ = mx + b.

What is a least squares regression line?

The least squares regression line is a straight line that best describes the relationship between two variables, usually called x (input) and y (output). “Best” means the line minimizes the total squared vertical distance between the observed points and the predicted values from the line.

In practical terms, this gives you a simple equation you can use to model trends, make predictions, and understand how strongly two variables move together. You’ll often see it written as:

ŷ = mx + b

  • m is the slope (how much y changes when x increases by 1)
  • b is the intercept (the expected y-value when x = 0)

Formulas used by the calculator

Slope and intercept

The calculator computes the line from your data using the standard least squares formulas:

  • m = (nΣxy - (Σx)(Σy)) / (nΣx² - (Σx)²)
  • b = (Σy - mΣx) / n

Goodness of fit

To help interpret quality, the tool also reports correlation and determination:

  • r: Pearson correlation coefficient (from -1 to +1)
  • : coefficient of determination (proportion of variance explained by the line)

How to use this calculator

  • Enter each point on a new line, such as 10, 14 or 10 14.
  • Use at least two points, but more points usually give a more useful model.
  • Click Calculate Regression Line.
  • Optionally enter an x-value to generate a prediction for y.
  • Review residuals in the output table to see how far each point is from the fitted line.

Interpreting your results

Slope (m)

If the slope is positive, y tends to increase as x increases. If negative, y tends to decrease as x increases. A slope near zero suggests little linear relationship.

Intercept (b)

The intercept is the model’s expected y-value at x = 0. It is mathematically required, but whether it has real-world meaning depends on your context.

R and R²

Values of |r| near 1 indicate a strong linear relationship. near 1 means the line explains most of the variation in y. Lower values suggest weaker linear fit or nonlinear behavior.

Common mistakes to avoid

  • Mixing formats: keep each line as one pair (x,y).
  • Using identical x-values: if all x values are the same, no valid regression line can be computed.
  • Ignoring outliers: a single extreme point can strongly influence the line.
  • Assuming causation: correlation and regression do not prove one variable causes the other.

When this tool is useful

This least squares regression line calculator is useful in finance, business, science, education, and personal projects. You can estimate trends in sales over time, compare test scores to study hours, model growth patterns, or build quick forecasting baselines.

For deeper analysis, you can extend this with confidence intervals, residual plots, and nonlinear models. But for quick linear trend estimation, this calculator gives you a fast and accurate starting point.

🔗 Related Calculators