Learn R Programming

gratia (version 0.9.0)

edf: Effective degrees of freedom for smooths and GAMs

Description

Extracts the effective degrees of freedom (EDF) for model smooth terms or overall EDF for fitted GAMs

Usage

edf(object, ...)

# S3 method for gam edf( object, select = NULL, smooth = deprecated(), type = c("default", "unconditional", "alternative"), partial_match = FALSE, ... )

model_edf(object, ..., type = c("default", "unconditional", "alternative"))

Arguments

object

a fitted model from which to extract smooth-specific EDFs.

...

arguments passed to methods.

select

character, logical, or numeric; which smooths to plot. If NULL, the default, then all model smooths are drawn. Numeric select indexes the smooths in the order they are specified in the formula and stored in object. Character select matches the labels for smooths as shown for example in the output from summary(object). Logical select operates as per numeric select in the order that smooths are stored.

smooth

[Deprecated] Use select instead. extracted. If NULL, the default, EDFs for all smooths will be returned.

type

character: which type of EDF to return. "default" returns the standard EDF; "unconditional" selects the EDF corrected for smoothness parameter selection, if available; "alternative" returns the alternative formulation for EDF from Wood (2017, pp. 252)

partial_match

logical; should smooths be selected by partial matches with select? If TRUE, select can only be a single string to match against.

Details

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})\).

Examples

Run this code
load_mgcv()
# \dontshow{
op <- options(cli.unicode = FALSE, pillar.sigfig = 5)
# }
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)
# \dontshow{
options(op)
# }

Run the code above in your browser using DataLab