Builds a GAM model in a step-wise fashion. For each "term" there is an
ordered list of alternatives, and the function traverses these in a greedy
fashion. Note: this is NOT a method for
step, which used to be a
generic, so must be invoked with the full name.
step.Gam( object, scope, scale, direction = c("both", "backward", "forward"), trace = TRUE, keep = NULL, steps = 1000, parallel = FALSE, ... )
An object of class
defines the range of models examined in the step-wise search.
It is a list of formulas, with each formula corresponding to a term in the
model. Each of these formulas specifies a "regimen" of candidate forms in
which the particular term may enter the model. For example, a term formula
As an alternative more convenient for big models, each list can have instead
of a formula a character vector corresponding to the candidates for that
term. Thus we could have
The supplied model
an optional argument used in the definition of the AIC statistic used to evaluate models for selection. By default, the scaled Chi-squared statistic for the initial model is used, but if forward selection is to be performed, this is not necessarily a sound choice.
The mode of step-wise search, can be one of
A filter function whose input is a fitted
The maximum number of steps to be considered. The default is 1000 (essentially as many as required). It is typically used to stop the process early.
Additional arguments to be passed on to
The step-wise-selected model is returned, with up to two additional
components. There is an
"anova" component corresponding to the steps
taken in the search, as well as a
"keep" component if the
keep= argument was supplied in the call.
We describe the most general setup, when
direction = "both". At any
stage there is a current model comprising a single term from each of the
term formulas supplied in the
scope= argument. A series of models is
fitted, each corrresponding to a formula obtained by moving each of the
terms one step up or down in its regimen, relative to the formula of the
current model. If the current value for any term is at either of the extreme
ends of its regimen, only one rather than two steps can be considered. So if
p term formulas, at most
2*p - 1 models are
considered. A record is kept of all the models ever visited (hence the
-1 above), to avoid repetition. Once each of these models has been
fit, the "best" model in terms of the AIC statistic is selected and defines
the step. The entire process is repeated until either the maximum number of
steps has been used, or until the AIC criterion can not be decreased by any
of the eligible steps.
Written by Trevor Hastie, following closely the design in the "Generalized Additive Models" chapter (Hastie, 1992) in Chambers and Hastie (1992).
Hastie, T. J. (1992) Generalized additive models. Chapter 7 of Statistical Models in S eds J. M. Chambers and T. J. Hastie, Wadsworth & Brooks/Cole.
Hastie, T. and Tibshirani, R. (1990) Generalized Additive Models. London: Chapman and Hall.
data(gam.data) Gam.object <- gam(y~x+z, data=gam.data) step.object <-step.Gam(Gam.object, scope=list("x"=~1+x+s(x,4)+s(x,6)+s(x,12),"z"=~1+z+s(z,4))) ## Not run: # Parallel require(doMC) registerDoMC(cores=2) step.Gam(Gam.object, scope=list("x"=~1+x+s(x,4)+s(x,6)+s(x,12),"z"=~1+z+s(z,4)),parallel=TRUE) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.