Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Spline Tuning and Uncertainty

The smoothing parameter determines how much curvature the estimate can use. Selecting it and describing the uncertainty of the resulting curve are separate tasks. A visually smooth fit can still be biased, and a narrow interval need not account for that bias.

The smoother matrix

For a fixed basis and penalty parameter, write

Aλ=B(B⊤B+λS)−1B⊤,y^=Aλy.A_\lambda=B(B^\top B+\lambda S)^{−1}B^\top,\qquad\widehat y=A_\lambda y.

The effective degrees of freedom are df⁡(λ)=tr⁡(Aλ)\operatorname{df}(\lambda)=\operatorname{tr}(A_\lambda). This measures how responsive the fitted values are to the observed responses. It need not equal the number of basis coefficients.

At small penalties, df approaches the rank of the unpenalized design. At large penalties, it approaches the dimension of the identifiable penalty nullspace. For the usual curvature penalty with an identifiable intercept and slope, that limit is two.

Validation criteria

Using the same fixed basis and the same numerical penalty in each omitted fit, the linear smoother identity gives

CV⁡(λ)=1n∑i{yi−y^i1−aii}2.\operatorname{CV}(\lambda)=\frac1n\sum_i\left\{\frac{y_i−\widehat y_i}{1−a_{ii}}\right\}^2.

The denominators must be nonzero and the omitted fitting problems must remain well defined. If preprocessing or basis construction is learned again in each fold, evaluate that complete procedure directly rather than assuming this shortcut still applies.

Generalized cross validation replaces individual leverages by their average:

GCV⁡(λ)=∥y−Aλy∥2/n{1−tr⁡(Aλ)/n}2.\operatorname{GCV}(\lambda)=\frac{\lVert y−A_\lambda y\rVert^2/n}{\{1−\operatorname{tr}(A_\lambda)/n\}^2}.

Search over a range of penalties. If the best score lies at the edge, examine whether the range was adequate. A low score obtained after searching is a selection result; independent assessment still requires a reserved test sample or an outer validation loop.

Sampling variation of the curve

Assume the true mean is BβB\beta and set M=B⊤B+λSM=B^\top B+\lambda S. Then

E(β^∣B)=M−1B⊤Bβ,E(\widehat\beta\mid B)=M^{−1}B^\top B\beta,
Var⁡(β^∣B)=σ2M−1B⊤BM−1.\operatorname{Var}(\widehat\beta\mid B)=\sigma^2M^{−1}B^\top BM^{−1}.

The covariance is not simply σ2M−1\sigma^2M^{−1}. The middle B⊤BB^\top B appears because the random part enters through B⊤yB^\top y.

At a new input x∗x_*,

f^(x∗)=b(x∗)⊤β^,\widehat f(x_*)=b(x_*)^\top\widehat\beta,
Var⁡{f^(x∗)∣B}=σ2b(x∗)⊤M−1B⊤BM−1b(x∗).\operatorname{Var}\{\widehat f(x_*)\mid B\}=\sigma^2b(x_*)^\top M^{−1}B^\top BM^{−1}b(x_*).

For normal errors and fixed λ\lambda, this is the exact sampling variance around the expectation of the smoothed estimate. The expectation can differ from the true curve because of shrinkage or an insufficient basis.

What an interval includes

A displayed band of the form f^(x)±1.96se⁡{f^(x)}\widehat f(x)\pm1.96\operatorname{se}\{\widehat f(x)\} is a pointwise approximation for the mean curve when smoothing bias is negligible. It is not automatically a simultaneous 95 percent band across every xx.

Predicting a new response adds its noise variance. With independent future errors, the variance around the expected prediction error includes the estimation variance plus σ2\sigma^2. Neither calculation automatically includes uncertainty from selecting λ\lambda on the same sample.

Estimating the noise variance

The lecture uses residual error with an effective degrees of freedom adjustment. For a fixed smoother and true mean μ\mu, the exact expectation is

E∥(I−A)y∥2=∥(I−A)μ∥2+σ2{n−2tr⁡(A)+tr⁡(A⊤A)}.E\lVert(I−A)y\rVert^2=\lVert(I−A)\mu\rVert^2+\sigma^2\{n−2\operatorname{tr}(A)+\operatorname{tr}(A^\top A)\}.

For ordinary least squares with the correct mean space, the bias term vanishes and A2=AA^2=A, recovering the familiar residual degrees of freedom. For a penalized spline neither simplification generally holds. Dividing RSS by n−tr⁡(A)n−\operatorname{tr}(A) is therefore a working adjustment, not a general proof of unbiasedness.