mfasiolo / qgam

Additive quantile regression R package
http://mfasiolo.github.io/qgam/
30 stars 7 forks source link

More careful calculation of penalized EDF #31

Open mfasiolo opened 5 years ago

mfasiolo commented 5 years ago

The calculation of the optimal loss smoothness requires calculating the number of effective degrees of freedom. In .getErrParam we currently do

# Fixing dimension d to EDF of Gaussian fit. 
# First use anova to find degrees of freedom of parametric terms in equation for location
# Then find EDF of smooth terms in equation for location. 
# unique() needed for "adaptive" smooths
  anv <- anova( gFit )
  d <- sum( anv$pTerms.df[ !grepl("\\.1", rownames(anv$pTerms.table)) ] )
  d <- d + sum( unique(pen.edf(gFit)[!grepl("s\\.1|te\\.1|ti\\.1|t2\\.1", names(pen.edf(gFit)))]) )

Using unique() avoids counting the edf of the same effect multiple times when using adaptive smooths and tensor product smooth, but might be problematic when using by-factor smooths, for example.