Should I use `select=TRUE` for `mgcv::gam` while comparing df? While running a GAM (Generalized Additive Model), I noticed that using select=TRUE inside mgcv:gam I get different df from logLik.gam than not using it. What is the actual reason behind it?
I need to compare the df form different model. In this purpose should I use select=TRUE or not?
Any suggestions is really appreciated.
 A: select = TRUE turns on additional penalties for the null spaces of all smooths in the current model. The null space of a spline is the span of functions that are not affected by the penalty. As they aren't affected by the penalty, the coefficients for these terms are not shrunk as part of the penalised likelihood maximisation. Hence any smooth can only be shrunk back to a linear function, not to a constant function, which would (effectively) remove the function from the model. The addition of a penalty on the null space(s) of the smooth(s) in the model allows these functions to be penalised during fitting, which can result in the shrinkage of specific terms to the extent that they can now be effectively removed from the model.
Hence select = TRUE allows for model selection to be performed on a GAM in a principled way without requiring a step-wise selection procedure of model terms.
Because the functions in the null space are being penalised when select = TRUE, it should not be unexpected that models fitted with select = TRUE would use fewer effective degrees of freedom (EDF) than otherwise equivalent models fitted with select = FALSE.
Here's an example to illustrate what is going on:
library("gratia")
library("mgcv")

df <- data_sim("eg1")

m1 <- gam(y ~ s(x0) + s(x1) + s(x2) + s(x3), data = df, method = "REML")
m2 <- update(m1, . ~ ., select = TRUE)

model_edf(m1, m2)

We see that m2, with select = TRUE uses fewer EDF than m1
> model_edf(m1, m2)                                                           
# A tibble: 2 × 2
  model   edf
  <chr> <dbl>
1 m1     16.1
2 m2     14.4

The reason fewer EDF are used is that $f_3(x_{3i})$ has been effectively shrunk out of the model, and $f_0(x_{0i})$ has been shrunk a little more than in m1. The other terms haven't changed all that much:
> edf(m1)                                                                     
# A tibble: 4 × 2
  smooth   edf
  <chr>  <dbl>
1 s(x0)   3.43
2 s(x1)   2.83
3 s(x2)   7.85
4 s(x3)   1.00
> edf(m2)                                                                     
# A tibble: 4 × 2
  smooth      edf
  <chr>     <dbl>
1 s(x0)  2.85    
2 s(x1)  2.79    
3 s(x2)  7.73    
4 s(x3)  0.000155

Whether or not to use select = TRUE comes down to whether you want to perform model selection or otherwise penalise the functions in the null space. If you aren't sure if all the smooth functions should even be included in the model, then it would make sense to use the additional penalties.
You haven't said why you want to compare the EDF of models you are fitting. Absent that information, I would suggest that it would be prudent to fit the same kind of model for each of your models. So I would use the same value of select across all the models I was wanting to compare. Whether you use select = TRUE or select = FALSE is a different question, one which you can hopefully answer on your own given the above description I gave of what this argument does.
