# Why doesn't penalized cubic regression reduce the number of knots in a GAM?

As far as I understand, cubic regression penalization prevents overfitting by reducing the number of knots by penalizing wiggliness. The supplied parameter k serves only as a starting points for choosing the knots.

From ?mgcv::choose.k:

In practice k-1 (or k) sets the upper limit on the degrees of freedom associated with an s smooth [...] However the actual effective degrees of freedom are controlled by the degree of penalization selected during fitting, by GCV, AIC, REML or whatever is specified.

However, with my model specifications, penalization does not seem to have an effect. The demo below starts and ends with 114 knots. Obviously I'm mistaken somewhere. What am I missing?

> require(mgcv)
> data(beavers)
> mod <- gam(temp ~ s(time, bs="cr", k = length(beaver1$$time)), data = beaver1) > length(mod$$smooth[[1]]\$xp)
[1] 114
> plot(mod, scheme = 1, residuals = T)


• What do you mean that it "starts and ends" with 114 knots? You're fitting a model that has 114 coefficients (including intercept); I don't see how there's a "start" or an "end". The penalization is working, but you're fitting the response to a temporal predictor that's sampled very finely as compared to the oscillations of the response, so it's basically just generating an interpolant. – Josh Feb 18 at 20:22

$$\min_{\beta} \sum(y_i- Z_i^T\gamma - X_i^T\beta)^2 + \lambda||\beta||_2$$
The $$X_i$$ are the cubic spline terms, the $$Z_i$$ are terms whose coefficients aren't being regularized. The last term is a penalty on the magnitude of the $$\beta$$ coefficients; the larger $$\lambda$$ is, the more the coefficients are shrunk towards zero. It's this last term that penalizes "wiggliness"; to see this, imagine what happens as $$\lambda \rightarrow \infty$$ - the fitted curve comes closer and closer to ignoring the $$X_i$$ altogether, which is about as non-wiggly (with respect to the $$X_i$$) as you can get - it's saying that the estimated function is constant with respect to changes in the $$X_i$$.