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
- Type x values, for example 1, 2, 3, 4, 5.
- Type y values, for example 2, 4, 5, 4, 5.
- Optionally, enter predict y at x.
- Press Calculate to see the result, and use Reset to start again.
| Input | What to enter | Allowed values |
|---|---|---|
| x values | Text, such as 1, 2, 3, 4, 5 | — |
| y values | Text, 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.
| Result | Value |
|---|---|
| Regression line | y = 2.2 + 0.6x |
| Slope | 0.6 |
| Intercept | 2.2 |
| r² | 0.6 |
| Predicted y | 5.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.
| Predict y at x | Regression line | Slope | Intercept |
|---|---|---|---|
| 3 | y = 2.2 + 0.6x | 0.6 | 2.2 |
| 6 | y = 2.2 + 0.6x | 0.6 | 2.2 |
| 12 | y = 2.2 + 0.6x | 0.6 | 2.2 |
| 24 | y = 2.2 + 0.6x | 0.6 | 2.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.
| Calculator | You enter | It returns |
|---|---|---|
| [Linear Regression Calculator](/statistics/linear-regression-calculator/) | x values and y values | Regression line |
| [Multiple Linear Regression Calculator](/statistics/multiple-regression-calculator/) | response values and predictor 1 | Coefficients (intercept, b₁, b₂ …) |
| [Correlation Coefficient Calculator](/statistics/correlation-coefficient-calculator/) | x values and y values | Correlation r |
| [Covariance Calculator](/statistics/covariance-calculator/) | x values and y values | Sample covariance |
| [R-Squared Calculator](/statistics/r-squared-calculator/) | x values and y values | R² |
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.
Related calculators
- 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.
- Covariance Calculator — Sample and population covariance.
- R-Squared Calculator — Coefficient of determination for a simple linear fit.
- Sum of Squares Calculator — Sum of squared deviations from the mean, and sum of squared values.
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.