Linear Regression Calculator

Fit a least-squares line to paired observations and calculate slope, intercept, R² and a prediction at a selected x value.

Predicted y on the fitted line9.5000

The input numbers, separated by commas or spaces.

One y value for each x value, in the same order.

The calculator uses the line to guess y at this x.

Predicted y on the fitted line

9.5000

  • Slope1.9000
  • Intercept0.0000
  • R²0.9627
  • Line of best fity = 0 + 1.9x

Ordinary least squares with an intercept. A fitted association is not causation. Predictions outside observed x values are extrapolations; this tool does not calculate prediction intervals.

How this was calculated

  1. Find the mean (the average) of the x values and of the y values: add them up and divide by how many there are.mean x = Σx ÷ n; mean y = Σy ÷ nPut in your numbers: (1 + 2 + 3 + 4) ÷ 4; (2 + 4 + 5 + 8) ÷ 4Answer: mean x = 2.5, mean y = 4.75
  2. The slope is how much y goes up when x goes up by 1. Compare how x and y move together with how much x spreads out.Slope = Σ(x − mean x)(y − mean y) ÷ Σ(x − mean x)².Put in your numbers: 9.5 ÷ 5Answer: 1.9
  3. The intercept is where the line crosses the y-axis: the y value when x is 0.Intercept = mean y − slope × mean x.Put in your numbers: 4.75 − 1.9 × 2.5Answer: 0
  4. Put your x value into the line to get the predicted y.Predicted y = intercept + slope × selected x.Put in your numbers: 0 + 1.9 × 5Answer: 9.5
  5. R² shows how well the line fits the points. 1 means every point sits on the line; 0 means the line does not help at all.R² = [Σ(x − mean x)(y − mean y)]² ÷ [Σ(x − mean x)² × Σ(y − mean y)²]Put in your numbers: 9.5² ÷ (5 × 18.75)Answer: 0.962666666667

Linear regression in simple words

Linear regression draws the straight line that fits a set of points best. You can then use the line to guess new values.

The line is written y = intercept + slope × x. The slope is how much y goes up when x goes up by 1. The intercept is where the line crosses the y-axis, when x is 0.

For example, with the points (1, 2), (2, 4), (3, 5) and (4, 8), the best line is y = 0 + 1.9x. So at x = 5 the line predicts y = 1.9 × 5 = 9.5.

R² tells you how close the points are to the line. 1 means they all sit exactly on it; close to 0 means the line does not describe them well.

Formula and method

Slope = Σ(x − x̄)(y − ȳ)/Σ(x − x̄)². Intercept = ȳ − slope × x̄. The prediction is intercept + slope × x.

Worked example

For x values 1, 2, 3 and y values 3, 5, 7, the fitted line is y = 1 + 2x with R² = 1.

Frequently asked questions

Does a high R² prove causation?

No. It describes fit within the observed sample. It does not establish causation or make extrapolation reliable, and this tool does not provide prediction intervals.

References

Last updated . Results are estimates for informational purposes only.