Linear Regression Calculator

Fit the least-squares line through paired data and get the equation, R², slope significance, predictions with intervals, residuals and a scatter plot.

Separate with commas, spaces or new lines.
Predicted y at x = 6.5
10.638095
95% prediction interval
7.2182 to 14.058mean response: 9.1852 to 12.091
Slope (b₁)
1.319048y changes by 1.319 per unit of x
Intercept (b₀)
2.064286predicted y at x = 0
R²
0.883888.38% of variation in y explained
Correlation (r)
0.9401
Std. error of estimate
1.265225
Slope 95% CI
0.8413 to 1.7968
p-value (slope ≠ 0)
0.000513
Regression lineŷ = 2.0643 + 1.319xR² = 0.8838, n = 8

Show the work

  1. Means: x̄ = 4.5, ȳ = 8 (n = 8)
  2. Sxx = Σ(x − x̄)² = 42 and Sxy = Σ(x − x̄)(y − ȳ) = 55.4
  3. Slope: b₁ = Sxy ÷ Sxx = 55.4 ÷ 42 = 1.319048
  4. Intercept: b₀ = ȳ − b₁x̄ = 8 − 1.319048 × 4.5 = 2.064286
  5. Residual sum of squares: SSE = Σ(y − ŷ)² = 9.604762; total SSyy = 82.68
  6. R² = 1 − SSE ÷ SSyy = 1 − 9.604762 ÷ 82.68 = 0.883832
  7. Standard error of the estimate: s = √(SSE ÷ (n − 2)) = √(9.604762 ÷ 6) = 1.265225
  8. SE of slope = s ÷ √Sxx = 0.195228; t = b₁ ÷ SE = 6.7564, p = 0.000513 (df = 6)
  9. Prediction: ŷ(6.5) = 2.064286 + 1.319048 × 6.5 = 10.638095
  10. 95% prediction interval for one new y: ŷ ± t* × s × √(1 + 1/n + (x₀ − x̄)²/Sxx) = 10.638095 ± 3.41986
2.557.51012.5150246810xy(1, 3.5)(2, 4)(3, 7.2)(4, 6.1)(5, 9.8)(6, 8.7)(7, 12.9)(8, 11.8)
Coefficients
TermEstimateStd. errortp-value
Intercept (b₀)2.0642860.9858552.09390.081159
Slope (b₁)1.3190480.1952286.75640.000513
Fit statistics: adjusted R² = 0.8645, F(1, 6) = 45.6494, p = 0.000513
#xyFitted ŷResidual y − ŷ
113.53.3833330.116667
2244.702381−0.702381
337.26.0214291.178571
446.17.340476−1.240476
559.88.6595241.140476
668.79.978571−1.278571
7712.911.2976191.602381
8811.812.616667−0.816667
Σ640

Linear regression finds the straight line that best summarizes how one variable changes with another. “Best” has a precise meaning: the line makes the sum of squared vertical distances from the points as small as possible. Paste your x and y values to get the regression equation, R², standard errors and p-values, a prediction with confidence and prediction intervals, the full residual table and a scatter plot with the fitted line.

How to use the linear regression calculator

  1. Enter the predictor values in X and the response values, in the same order, in Y.
  2. Optionally enter an x value to predict y. Leave it blank to skip the prediction.
  3. Choose the confidence level for the slope interval and the prediction intervals (95% is standard).
  4. Read the equation on the tape, check the scatter plot for curves or outliers, and use the residual table to see how far each point falls from the line.

Least-squares formulas

With Sxx = Σ(x − x̄)² and Sxy = Σ(x − x̄)(y − ȳ):

b₁ = Sxy ÷ Sxx  ·  b₀ = ȳ − b₁x̄  ·  ŷ = b₀ + b₁x

Fit quality and uncertainty come from the residuals e = y − ŷ:

R² = 1 − Σe² ÷ Σ(y − ȳ)²  ·  s = √(Σe² ÷ (n − 2))  ·  SE(b₁) = s ÷ √Sxx

A prediction at x₀ has the interval ŷ ± t* × s × √(1 + 1/n + (x₀ − x̄)²/Sxx); dropping the “1 +” gives the narrower interval for the mean response.

Worked example

A small business records monthly advertising spend (x, in thousands of dollars) and sales (y, in thousands):

x 1 2 3 4 5 6 7 8
y 3.5 4.0 7.2 6.1 9.8 8.7 12.9 11.8
  1. Means: x̄ = 4.5 and ȳ = 8.0.
  2. Sxx = 42 and Sxy = 55.4.
  3. Slope: 55.4 ÷ 42 = 1.3190. Intercept: 8.0 − 1.3190 × 4.5 = 2.0643.
  4. Equation: ŷ = 2.0643 + 1.3190x. Each extra $1,000 of advertising goes with about $1,319 more in sales.
  5. SSE = 9.6048 against a total of 82.68, so R² = 0.8838.
  6. The slope’s standard error is 0.1952, so t = 6.756 with 6 df and p = 0.0005. The 95% interval for the slope is 0.841 to 1.797.
  7. At x = 6.5, the predicted sales are 10.64. The 95% interval for the average month at that spend is 9.19 to 12.09, while a single future month could plausibly land anywhere from 7.22 to 14.06.

Checking the fit

Look at the residuals

A good linear fit leaves residuals that scatter randomly around zero. Patterns signal problems: a curve (residuals positive at both ends, negative in the middle) means the relationship is not linear; a funnel shape means the spread grows with x. Residuals always sum to zero in least squares, which the table confirms.

R² is not everything

R² can be high for a curved relationship and low for a correct model with noisy data. It also always rises when data cover a wider x range. Judge a model by the residual pattern, the size of s in the units of y, and whether the slope makes sense.

Influential points

A point far out on the x axis can pull the line toward itself. Try removing it and refitting; if the slope changes a lot, report both fits. The outlier calculator helps flag extreme values first.

Regression and correlation

In simple regression, R² equals the square of Pearson’s r, and the slope’s t-test is identical to the test of r = 0. For the correlation alone, use the correlation coefficient calculator. To smooth a time series instead of fitting a line, try the moving average calculator.

Frequently asked questions

What does the slope of a regression line mean?

It is the predicted change in y for a one-unit increase in x. A slope of 1.319 means that each extra unit of x is associated with about 1.32 more units of y on average. Its sign matches the sign of the correlation.

What is a good R² value?

There is no universal cutoff. Controlled lab measurements often reach 0.95 or higher, while models of human behavior may be useful at 0.2. R² tells you the share of variation explained, not whether the model is correct; a curved pattern can still give a high R² with a straight line.

What is the difference between a confidence interval and a prediction interval?

The confidence interval brackets the average y for all cases with that x value. The prediction interval brackets a single new observation, so it also includes the scatter of individual points around the line and is always wider.

Can I use the line to predict outside my data?

You can compute a value, but it is extrapolation: it assumes the straight-line pattern continues where you have no evidence. Predictions far outside the observed x range are often badly wrong. The calculator warns you when x is outside the range.

Does it matter which variable is x and which is y?

Yes. Least squares minimizes vertical distances, so regressing y on x gives a different line from regressing x on y unless the correlation is perfect. Put the variable you want to predict in Y and the predictor in X.

Last reviewed October 2026 by the CalcFluent editorial team. How we check our calculators.