Each method replaces age by a few derived columns b1(age), …, bK(age) and fits wage by least squares (7.7). The band is the fitted curve ± 2 pointwise standard errors, √(ℓ0TCℓ0) with C the covariance matrix of the coefficients. Change the method and the degrees of freedom and compare how the curve, the width of the band at the two ends, and the ten-fold cross-validation error respond.
All fits use the 3000 men of the Wage data. Knots of the splines sit at equally spaced quantiles of age (R's bs(age, df) and ns(age, df)); step functions use equal-width bins (R's cut(age, K)). Least squares is solved by a QR decomposition. Cross-validation: ten folds fixed by row number, the basis rebuilt from each training part.
code/ch07_moving_beyond_linearity.py (Figures 7.1, 7.2, 7.4–7.7) and the labs ch07_lab.R, ch07_lab.py.