Skip to content
CalculatorAtlas

Least Squares Regression Calculator

Tested

Fit the least-squares regression line to paired data and read off the slope, intercept and a prediction.

Tested, not yet published. The formula for this calculator is implemented and passes its automated checks. This page stays non-indexable until it is reviewed and published.

Results

Enter your values and press Calculate. Results appear here.

  • • Result

Quick answer

Least-squares regression fits y = a + bx with b = Sxy ÷ Sxx and a = ȳ − b·x̄. For x = 1 to 5 and y = 2, 4, 5, 4, 5, the line is y = 2.2 + 0.6x with r² = 0.6, predicting y = 5.8 at x = 6.

Enter equal-length x and y lists and optionally an x to predict. The calculator returns the line, slope, intercept, r² and the prediction.

Related tools: Linear Regression Calculator: Least-squares line y = a + bx through paired data. Multiple Linear Regression Calculator: Least-squares coefficients and R² for up to three predictors. Correlation Coefficient Calculator: Pearson correlation of two variables.

How to use the Least Squares Regression Calculator

  1. Type x values, for example 1, 2, 3, 4, 5.
  2. Type y values, for example 2, 4, 5, 4, 5.
  3. Optionally, enter predict y at x.
  4. Press Calculate to see the result, and use Reset to start again.
Inputs of the Least Squares Regression Calculator
InputWhat to enterAllowed values
x valuesText, such as 1, 2, 3, 4, 5—
y valuesText, such as 2, 4, 5, 4, 5—
Predict y at x (optional)A number—

Formula and method

Formula

b = Sxy ÷ Sxx; a = ȳ − b·x̄; r² = Sxy² ÷ (Sxx·Syy)

IEEE-754 double precision; shown to at most 6 decimal places.

Ordinary least squares for one predictor.

Worked examples

This example is verified: each one is an automated test case that the live calculator must reproduce exactly.

Example 1

Inputs: x values = 1,2,3,4,5; y values = 2,4,5,4,5; Predict y at x = 6.

Results of example 1
ResultValue
Regression liney = 2.2 + 0.6x
Slope0.6
Intercept2.2
r²0.6
Predicted y5.8

The first line is the headline result (regression line). Below it the least Squares Regression Calculator lists slope, intercept, r² and predicted y, which describe the same case from other angles. IEEE-754 double precision; shown to at most 6 decimal places.

Worked example

x̄ = 3, ȳ = 4, Sxy = 6 and Sxx = 10, so b = 0.6 and a = 4 − 1.8 = 2.2. At x = 6: 2.2 + 3.6 = 5.8.

Use with care

The line minimises the sum of squared vertical errors. x must vary. Predicting outside the x range (extrapolating) is risky, and r² = 0.6 says 60% of the variation in y is explained by x.

How the result changes with predict y at x

Holding every other input at the first worked example, this table changes only predict y at x. It shows how sensitive the answer is to that one value; each row was produced by running this calculator.

How the result changes with predict y at x
Predict y at xRegression lineSlopeIntercept
3y = 2.2 + 0.6x0.62.2
6y = 2.2 + 0.6x0.62.2
12y = 2.2 + 0.6x0.62.2
24y = 2.2 + 0.6x0.62.2

What happens with invalid input

These messages are produced by the calculator itself, so you know what to fix.

  • x values: entering "2,2,2" shows "x values must not all be equal." beside that field and no result.

Choosing between the Least Squares Regression Calculator and similar calculators

Each row shows what a related calculator on this site asks for and what it returns, so you can pick the one that matches your question.

Choosing between the Least Squares Regression Calculator and similar calculators
CalculatorYou enterIt returns
[Linear Regression Calculator](/statistics/linear-regression-calculator/)x values and y valuesRegression line
[Multiple Linear Regression Calculator](/statistics/multiple-regression-calculator/)response values and predictor 1Coefficients (intercept, b₁, b₂ …)
[Correlation Coefficient Calculator](/statistics/correlation-coefficient-calculator/)x values and y valuesCorrelation r
[Covariance Calculator](/statistics/covariance-calculator/)x values and y valuesSample covariance
[R-Squared Calculator](/statistics/r-squared-calculator/)x values and y valuesR²

Background: regression and correlation

Least squares chooses the line that minimises the sum of the squared vertical distances from the points. The slope is the sum of the cross-products of the deviations divided by the sum of the squared x deviations, and the intercept is the mean of y minus the slope times the mean of x.

For simple regression R² is the square of the correlation coefficient r, the share of the variation in y that the line explains. R² has no sign, so the sign of the slope tells you whether the relationship rises or falls. A strong fit does not prove one variable causes the other.

Assumptions and limitations

  • x must vary

If a required value is empty, not a number, or outside its allowed range, the form marks that field with a message and shows no result instead of a misleading number. The automated checks deliberately try invalid entries for x values to confirm this.

Frequently asked questions

What does the slope mean?

The average change in y per unit of x.

What is a residual?

The difference between data and line.

How is it different from correlation?

It gives the line, not just the strength.

What does the Least Squares Regression Calculator calculate?

Fit the least-squares regression line to paired data and read off the slope, intercept and a prediction. It returns Regression line, Slope, Intercept, r² and Predicted y.

What formula does the Least Squares Regression Calculator use?

b = Sxy ÷ Sxx; a = ȳ − b·x̄; r² = Sxy² ÷ (Sxx·Syy). Ordinary least squares for one predictor.

What do I need to enter in the least Squares Regression Calculator?

You enter x values and y values. Optional: Predict y at x.

How is the result rounded or limited?

IEEE-754 double precision; shown to at most 6 decimal places. x must vary.

What is an example of a least Squares Regression result?

With x values 1,2,3,4,5, y values 2,4,5,4,5 and predict y at x 6, the regression line is y = 2.2 + 0.6x.

Sources

  • NIST/SEMATECH e-Handbook of Statistical Methods (itl.nist.gov/div898/handbook)
  • Standard textbook definitions (e.g. Moore, McCabe & Craig, Introduction to the Practice of Statistics)

Content last reviewed 2026-11-04. Formulas and worked examples are checked by automated tests against independently computed values.