Linear regression in this visualization
Simple linear regression predicts from with the least-squares line : the straight line with the smallest sum of squared residuals, where a point's residual is how far it lies above the line (negative below). With a few points each residual carries a square, so the sum is an area you can see. You can shift and turn a line of your own to look for the least, and compare the fitted line with a simulated cloud of 1000 points.
Why does the line pass through the center ? Write any line as , with its height above . Its residuals add up to , and its sum of squares splits in two:
Here , and are the sums of squared and multiplied deviations from the means. The first part depends only on the height and the second only on the slope, so at any slope the best height is : the best line passes through the center, and its residuals add up to 0. Turned about the center, the sum follows the parabola . When the values are not all equal, its single lowest point is at .
What does measure? The flat line is the parabola at slope 0, and its sum of squares is the total variation . The fitted line leaves ; when the values vary, is the share of the variation in that it accounts for. When both coordinates vary, , so a correlation of 0.5 accounts for only a quarter. Accounting for is fitting, not causing.
Why is the line flatter than the cloud? In standard units its predictions are , so when a point away from gets a prediction fewer standard deviations from than it lies from . In an oval cloud such as the simulated one, the SD line, with slope , runs along the cloud as the eye sees it; the regression line is flatter. Nothing pulls the data back: the effect holds for any such data, and predicting from shows it the other way, with a second line through the center that is steeper on the plot. In such a cloud, averages of in narrow strips of show the effect, close to the regression line but not exactly on it. The name comes from Francis Galton's 1886 study of heights: the children of very tall or very short parents were on average less extreme.
When can the line mislead? Raising one point by 1 raises its own fitted value by its leverage , which grows with the distance from . A point alone far out in can have leverage near 1: the line follows it, so even when it disagrees with every other point its own residual can look small, and even in a large cloud such a point can turn the line. And can be close to 1 while the residuals run positive at both ends and negative in the middle, a curve that no straight line follows.
Things to notice
- The squares are drawn square on the screen whatever the scales of the axes, so their areas compare like .
Controls
- On the cloud, pressing one of its points shows its residual and leverage; pressing empty space adds a point of your own.
- With the keyboard, your line's pivot moves with ↑ ↓ and its knob turns 1° a step; a step across the center or a level line stops there, and so does one across the least-squares slope while answers are shown.