Linear modelling: a least-squares approach

Chapter 1 · Model: t = w0 + w1·(x − c), where x is the Olympic year, c is and t the winning time in seconds. Move the sliders to fit a line by eye, then compare with the least-squares solution.

your line   least-squares fit   ● Olympic winners (data: olympics.mat)

w0 is the predicted time at x = c; w1 tilts the line about that point. Untick "Count years from 1900" to use the raw year as in the book (c = 0): then w0 is the value at year 0, far off the plot, so w1 appears to shift the line and the two parameters trade off.

Your loss, L = (1/N) Σ (tn − w0 − w1(xn − c))²:
The least-squares solution minimises L. Setting ∂L/∂w0 = 0 and ∂L/∂w1 = 0 gives w1 = (mean(xt) − mean(x)·mean(t)) / (mean(x²) − mean(x)²) and w0 = mean(t) − w1·(mean(x) − c). The slope w1 is the same whichever c you pick.