Linear Regression Calculator
Fitting the Best Straight Line Through Data
Given a scatter of paired (x, y) points, simple linear regression finds the single straight line that minimizes the total squared vertical distance between the line and every observed point — the least-squares criterion. That line becomes both a description of the relationship in the data and a prediction tool for new x values.
The Formula
slope (b) = Σ((x−x̄)(y−ȳ)) / Σ(x−x̄)²
intercept (a) = ȳ − b·x̄
Regression equation: y = bx + a
intercept (a) = ȳ − b·x̄
Regression equation: y = bx + a
Worked Example
x = 1, 2, 3, 4, 5. y = 2, 4, 5, 4, 5.
| Quantity | Value |
|---|---|
| Slope | 0.6000 |
| Intercept | 2.2000 |
| R² | 0.6000 |
| Regression equation | y = 0.6x + 2.2 |
| Predicted y at x = 6 | 5.80 |
Computed directly from the calculator's least-squares formula.
Where This Calculation Matters
- Forecasting and trend extrapolation — projecting sales, costs, or measurements forward based on a historical linear trend.
- Calibration curves — converting an instrument reading (x) into a real-world measurement (y) using a line fit from known calibration points, a routine step in laboratory science.
- Establishing a baseline relationship — before trying a more complex model, a simple linear fit shows whether a straight-line relationship already captures most of the pattern (via R²).
Note: Extrapolating far beyond the range of the observed x values assumes the linear relationship continues to hold, which is often not a safe assumption.
How to Use This Calculator
- Enter the X values as a comma-separated list.
- Enter the Y values as a comma-separated list, in the same order (at least 2 paired values).
- Optionally enter a specific X value to predict its corresponding Y.
- Select Calculate to get the slope, intercept, R², and regression equation.
Related Calculations
To check how strong the linear relationship is before fitting, use the Pearson Correlation Calculator. For a binary outcome variable instead of a continuous one, see the Logistic Regression Calculator.