Drag points and read the least squares line and R squared.
Linear Regression Playground simulator
Tap to add a point. Drag a point to move it.
This simulation needs a modern browser with canvas support. The measurements and formula below still describe the physics.
Live measurements
Controls
Formula
y = mx + b
- m Slope
- —
- b Intercept
- —
Observations
What's happening
Real-world examples
Five point line
The default points give y = 0.91x + 1.11 and R² = 0.880. The largest gap is 0.85 at (4, 3.9).
A perfect line
Points (1, 1), (2, 2), (3, 3), and (4, 4) sit on y = x. The slope is 1, the intercept is 0, and R² is 1.
One outlier
The outlier preset adds (5, 1) as point 6. The slope drops to about 0.33 and R² drops to about 0.089.
Two points
Any two points report R² = 1, because one line passes through both. A third point is what can miss the line.
▸ More about
Uses of linear regression calculator
- Checking a lab scatter plot before quoting a slope
- Showing a class why one outlier moves a line of best fit
- Comparing a hand-drawn line with the least squares line
linear regression calculator pitfalls
- Reading R squared as the size of a residual
- Trusting a perfect fit from only two points
- Letting one outlier set the slope
linear regression calculator questions (7)
What is a least squares line?
A least squares line is the straight line with the smallest sum of squared residuals. The five default points are (1, 2.2), (2, 2.8), (3, 4.1), (4, 3.9), and (5, 6.2). Their line of best fit is y = 0.91x + 1.11. The slope is 0.91, the intercept is 1.11, and R² is 0.880.
What is the difference between R squared and a residual?
R squared scores the whole line, and a residual is the vertical miss at one point. On the default points R² is 0.880. Point 4, which is (4, 3.9), still has an absolute residual of 0.85. A high R squared does not make every residual small.
Why do two points always show a perfect fit?
Two points always show a perfect fit, since one line passes through both and R² becomes 1. The perfect preset uses (1, 1), (2, 2), (3, 3), and (4, 4), and R² is exactly 1. Add a third point before you trust the slope, because two points always lie on a line.
How does one outlier change this line?
The outlier preset keeps the five default points and adds (5, 1) as point 6. The slope falls from 0.91 to about 0.33, and the intercept rises from 1.11 to about 2.28. R² falls from 0.880 to about 0.089, and point 6 has an absolute residual near 2.91. Letting one outlier set the slope is why that preset exists.
What does the largest residual on the default points mean?
The largest absolute residual on the default points is 0.85, at point 4. At x = 4 the fitted line predicts about 4.75. The point is (4, 3.9), so it sits 0.85 below that prediction.
How do I add and move points?
Tap empty space to add a point, up to eight, and drag a point to move it. Both axes run from 0 to 10, and a drag keeps every point inside that square. Checking a lab scatter plot before quoting a slope is the same gesture. Move the doubtful point and read the new fitted slope.
Does this fit more than one input?
This page fits one line, y = mx + b, and does not run multiple or logistic regression. Each point is a single pair, and eight points is the maximum. Comparing a hand-drawn line with the least squares line takes one look at the canvas.