Quick answer
Least-squares line y = a + bx through paired data. Enter x values and y values and the linear regression calculator returns regression line, slope and intercept.
Related tools: Least Squares Regression Calculator: Fit the least-squares regression line to paired data and read off the slope, intercept and a prediction. Multiple Linear Regression Calculator: Least-squares coefficients and R² for up to three predictors. Correlation Coefficient Calculator: Pearson correlation of two variables.
This page covers the same calculation as the least squares regression page; the two give identical results.
How to use the Linear 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 linear 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.
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 Linear 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 |
|---|---|---|
| [Least Squares Regression Calculator](/statistics/least-squares-regression/) | 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 Linear Regression Calculator calculate?
Least-squares line y = a + bx through paired data. It returns Regression line, Slope, Intercept, r² and Predicted y.
What formula does the Linear 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 linear 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 linear 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
- Least Squares Regression Calculator — Fit the least-squares regression line to paired data and read off the slope, intercept and a prediction.
- 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.
- Linear Interpolation Calculator — Interpolate a value between two known points.
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.