Expand the regression function in the cosine basis, φ1 = 1, φj(x) = √2 cos((j − 1)πx). The coefficients Zj = n−1 Σ Yi φj(xi) are close to independent N(θj, σ²/n): regression has become the normal means problem. A modulator b shrinks them, θ̂j = bj Zj, and Stein's unbiased risk estimate picks b: keep the first J terms (nested), a decreasing sequence (monotone), or one common factor (James–Stein). The noise level comes from the last quarter of the coefficients, where there is no signal left.
σ̂² = (n/Jn) Σj > n − Jn Zj² with Jn = n/4. Estimated risk of the nested modulator: R̂(J) = Jσ̂²/n + Σj > J(Zj² − σ̂²/n)+. The monotone modulator is the pooled-adjacent-violators fit of gj = 1 − σ̂²/(nZj²) with weights Zj². The band is r̂(x) ± c σ̂ ‖ℓ(x)‖ with c from the tube formula (shown for nested fits). Glass and motorcycle data have irregular designs: the cosines are first made orthonormal at the data points by Gram–Schmidt (Section 8.3); for the glass data J is searched up to √n.
code/ch08_orthogonal_functions.py (coefficients, sigma2_tail, nss_risk, pav, mon_modulator, band, ball_radius, gram_schmidt, react_irregular).