Advertisement

Least squares regression line calculator

Enter matching x and y lists. Every pair has equal weight. The output includes a residual table for checking the fitted line.

Calculator

Fitted slope
1.50000000
Fitted intercept
0.66666667
Pearson correlation r
0.98198051
R squared
0.96428571
Sum of squared residuals
0.16666667
Predicted y
6.66666667
Observation count
3.00000000
Mean x
2.00000000
Mean y
3.66666667
x, observed y, fitted y, residual
1, 2, 2.16666666667, -0.166666666667; 2, 4, 3.66666666667, 0.333333333333; 3, 5, 5.16666666667, -0.166666666667

Advertisement

How this calculator works

Ordinary least squares minimises squared vertical residuals. The fitted line passes through the means of x and y. Correlation and R squared measure linear association when both variables vary; they are omitted for constant y. The residual table preserves input order and helps identify mismatched data or large deviations. This engine supplies numeric summaries, not a scatter chart; use a plotting tool to inspect curvature and outliers before trusting a linear model.

Formula

m = sum((x-xMean)(y-yMean))/sum((x-xMean)^2); b = yMean - m xMean; r = Sxy/sqrt(Sxx Syy); SSE = sum((y - fitted y)^2).

Worked example

For (1, 2), (2, 4) and (3, 5), m = 1.5 and b = 2/3. The residuals are -1/6, 1/3 and -1/6, giving SSE = 1/6 and R squared = 27/28.

Advertisement

Frequently asked questions

Can I fit a vertical line?

No. Ordinary y-on-x regression requires variation in x and minimises vertical errors, not perpendicular distances.

Does high correlation prove causation?

No. Association can arise from confounding or coincidence. The fit alone does not establish a causal relationship.

Are repeated observations allowed?

Yes. Repeated pairs receive additional weight because each is treated as an observation.

Should I extrapolate?

A prediction outside the observed x range assumes the same linear relationship continues. That assumption may fail.

Sources

Advertisement