dfgam {flexOR} | R Documentation |
dfgam: Degrees of Freedom Selection for GAM Models
Description
Computes the degrees of freedom for specified non-linear predictors in a GAM model. The user can choose between AIC (Akaike Information Criterion), AICc (AIC corrected for small sample sizes), or BIC (Bayesian Information Criterion) as the selection criteria. This function is useful for determining the appropriate degrees of freedom for smoothing terms in GAMs.
Usage
dfgam(
response,
nl.predictors,
other.predictors = NULL,
smoother = "s",
method = "AIC",
data,
step = NULL
)
Arguments
response |
The response variable as a formula. |
nl.predictors |
A character vector specifying the non-linear predictors. |
other.predictors |
A character vector specifying other predictors if needed. |
smoother |
The type of smoothing term, currently only "s" is supported. |
method |
The selection method, one of "AIC", "AICc", or "BIC". |
data |
The data frame containing the variables. |
step |
The step size for grid search when there are multiple non-linear predictors. |
Value
A list containing the following components:
-
fit
: The fitted GAM model. -
df
: A numeric vector of degrees of freedom for each non-linear predictor. -
method
: The selection method used (AIC, AICc, or BIC). -
nl.predictors
: The non-linear predictors used in the model. -
other.predictors
: Other predictors used in the model if specified.
Examples
# Load dataset
library(gam)
data(PimaIndiansDiabetes2, package="mlbench");
# Calculate degrees of freedom using AIC
df2 <- dfgam(
response="diabetes",
nl.predictors=c("age", "mass"),
other.predictors=c("pedigree"),
smoother="s",
method="AIC",
data=PimaIndiansDiabetes2
);
print(df2$df);