Lab · c08.s04.L1

Least-squares drag

The fit is where the residual stops leaning on either column of the design matrix; two gauges read zero together only at the best line.

Question: Where does the least-squares formula come from?

Least-squares dragSix numbered points scatter around a solid russet candidate line, with a short vertical residual stick from each point to the line. Two gauges show the residual sum and the residual weighted by x. Both needles read zero only when the candidate line lies on the dashed navy best fit. Tilting the line, shifting it, or moving one point pushes the needles away and raises the printed squared error, which is smallest at the fit.Least-squares dragResidual r = y − (m x + b); the two gauges print the entries of Aᵀryx0.00.51.01.52.02.53.03.54.04.55.05.50.01.02.03.04.05.0Residual sum r·1−13.513.50Residual weighted by x r·x−42.542.50Squared errorBest-fit SSECandidate lineslopeinterceptBest-fit linecandidate linebest fit1234566.9790481.4190481.071429tilt 0.21.138095shift 0.4y = 0.871429 x + 0.738095point 3 · x = 2.0 · height 1.5-5.4-17.0
Synthetic Synthetic: six points drawn once from a seeded generator and snapped to a half-unit grid. The arithmetic is exact least squares; the data are not measurements.
Lab controls
2 point

Left/Right step 1; Home 0; End 5

1.5 y

Up/Down step 0.5; Page Up/Down step 1.0; Home 0.5; End 5.5

0.2 slope

Left/Right step 0.1; Page Up/Down step 0.3; Home -0.5; End 0.5

0.4 intercept

Up/Down step 0.2; Page Up/Down step 0.6; Home -1.0; End 1.0

Frame 1 of 11: The line you are givenThe stored default: the candidate line is tilted +0.2 and shifted +0.4 away from the best fit. Both needles sit off zero: the residual sum reads −5.4 and the residual weighted by x reads −17.0, so the residual still leans on both columns of the design matrix. The squared error is 6.979048, above the best-fit 1.419048.

The line you are given. The stored default: the candidate line is tilted +0.2 and shifted +0.4 away from the best fit. Both needles sit off zero: the residual sum reads −5.4 and the residual weighted by x reads −17.0, so the residual still leans on both columns of the design matrix. The squared error is 6.979048, above the best-fit 1.419048.

Keyboard: Space plays or pauses, Left and Right step, Home goes to the first frame, End goes to the last frame.

Text description of this lab

Six numbered points scatter around a solid russet candidate line, with a short vertical residual stick from each point to the line. Two gauges show the residual sum and the residual weighted by x. Both needles read zero only when the candidate line lies on the dashed navy best fit. Tilting the line, shifting it, or moving one point pushes the needles away and raises the printed squared error, which is smallest at the fit.

Return to the section that hosts this lab

Caption status: synthetic. Every lab declares one of published, re-simulated, schematic, synthetic or interpolated.