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,
select = NULL,
smooth = deprecated(),
type = c("default", "unconditional", "alternative"),
partial_match = FALSE,
...
)
model_edf(object, ..., type = c("default", "unconditional", "alternative"))
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
\mathrm{EDF} = 2\mathrm{tr}(\mathbf{F}) -
\mathrm{tr}(\mathbf{FF}),
where
\mathrm{tr}
is the matrix trace and \mathbf{F}
is a matrix
mapping un-penalized coefficient estimates to the penalized coefficient
estimates. The trace of \mathbf{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, select = 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.