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

Worked Example

x = 1, 2, 3, 4, 5. y = 2, 4, 5, 4, 5.

Linear regression fit result
QuantityValue
Slope0.6000
Intercept2.2000
0.6000
Regression equationy = 0.6x + 2.2
Predicted y at x = 65.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

  1. Enter the X values as a comma-separated list.
  2. Enter the Y values as a comma-separated list, in the same order (at least 2 paired values).
  3. Optionally enter a specific X value to predict its corresponding Y.
  4. 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.