edf | R Documentation |
Extracts the effective degrees of freedom (EDF) for model smooth terms or overall EDF for fitted GAMs
edf(object, ...) ## S3 method for class 'gam' edf( object, smooth = NULL, type = c("default", "unconditional", "alternative"), ... ) model_edf(object, ..., type = c("default", "unconditional", "alternative"))
object |
a fitted model from which to extract smooth-specific EDFs. |
... |
arguments passed to methods. |
smooth |
character; a vector of smooth terms whose EDFs will be
extracted. If |
type |
character: which type of EDF to return. |
Multiple formulations for the effective degrees of freedom are
available. The additional uncertainty due to selection of smoothness
parameters can be taken into account when computing the EDF of smooths.
This form of the EDF is available with type = "unconditional"
.
Wood (2017; pp. 252) describes an alternative EDF for the model
EDF = 2 * tr(F) - tr(F),
where \mathrm{tr} is the matrix trace and F is a matrix mapping un-penalized coefficient estimates to the penalized coefficient estimates. The trace of F is effectively the average shrinkage of the coefficients multipled by the number of coefficients (Wood, 2017). Smooth-specific EDFs then are obtained by summing up the relevent elements of \mathrm{diag}(2\mathbf{F} - \mathbf{FF}).
load_mgcv() df <- data_sim("eg1", n = 400, seed = 42) m <- gam(y ~ s(x0) + s(x1) + s(x2) + s(x3), data = df, method = "REML") # extract the EDFs for all smooths edf(m) # or selected smooths edf(m, smooth = c("s(x0)", "s(x2)")) # accounting for smoothness parameter uncertainty edf(m, type = "unconditional") # over EDF of the model, including the intercept model_edf(m) # can get model EDF for multiple models m2 <- gam(y ~ s(x0) + s(x1) + s(x3), data = df, method = "REML") model_edf(m, m2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.