Roughness-matrix formula for a natural cubic smoothing spline (source code)

= Roughness-matrix formula for a natural cubic smoothing spline
{title2=$A_\lambda=(I+\lambda K)^{-1}$}

For distinct ordered observations $x_i$, let $s_u$ be their <natural cubic spline interpolant> with values $u_i$. Its roughness is a <quadratic form>, $\int(s_u'')^2=u^TKu$, where $K$ is positive semidefinite and its nullspace consists of vectors sampled from affine functions. Minimizing <penalized least squares> $\|y-u\|^2+\lambda u^TKu$ gives $\widehat u=(I+\lambda K)^{-1}y$. Thus the <smoothing matrix> is $A_\lambda=(I+\lambda K)^{-1}$ and its <effective degrees of freedom> are $\operatorname{tr}(A_\lambda)$. As $\lambda\downarrow0$ the fit approaches interpolation and the trace approaches $n$; as $\lambda\to\infty$ it approaches the least-squares affine line and the trace approaches $2$.