Category: Statistics Level: 301
ŷ = a + bx; b = Sxy / Sxx = 168/42 = 4
The least squares line passes through the center of the data and makes the total of the squared vertical misses, the residuals, as small as possible.
Each dot is one student: hours studied across, test score up. The dots drift upward, so more study goes with higher scores, on average.
n = 8 students
Average the x values and the y values. The best line always passes through this center point.
mean of x = 4.5; mean of y = 64
The slope compares how x and y move together with how x moves alone. Then the line goes through the center.
b = 168/42 = 4, a = 64 - 4 · 4.5 = 46
A residual is the vertical miss: actual minus predicted. Dots above the line miss high (green), dots below miss low (red), and they add to zero.
residual = y - ŷ; ∑ residuals = 0
Draw each residual as a square. Least squares makes the total area as small as it can be. Tilt the line steeper through the center and the total jumps from 84 to 126.
SSE = ∑ (y - ŷ)2 = 84
For a student who studies 9 hours, read the line at x = 9. Predictions past the data are guesses, so trust them less the farther you go.
ŷ = 46 + 4 × 9 = 82
cd svg-generator python3 -m svgmath render linear-regression --out /tmp/linear-regression
Source: svgmath/diagrams/statistics.py