Build a GLM Model in a Step-Wise Fashion

DESCRIPTION:
Automatically adds and removes terms from a given GLM object to construct a new GLM model in "stepwise" fashion.

USAGE:
step.glm(object, scope, scale, direction="both", trace=T, keep, steps)

REQUIRED ARGUMENTS:
object:
An object of class glm or its inheritant, an lm object.

OPTIONAL ARGUMENTS:
scope:
defines the range of models examined in the step-wise search. The most general form for scope is a list consisting of two formulas, one named "upper", the other "lower". These define the range of models to be considered for selection, and only their right hand sides are of relevance. All models considered have to include the terms specified in scope$lower, and have to be included in those in scope$upper. The supplied model object is used as the starting model, and hence there is the requirement that it lies between $upper and $lower.

If scope is missing, the search defaults to a backward step-wise search, using formula(object) as the upper scope, and the NULL model as the lower scope. If scope is a single formula object, it is assumed to be the upper model. Any "." in the scope formula is interpreted relative to the formula in object.

scale:
an optional argument used in either the definition of the AIC statistic, as well as the Cp statistic used in the score tests for selecting the glm models at each step. 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.
direction:
The mode of step-wise search, can be one of "both", "backward", or "forward", with a default of "both". If scope is missing, the default for direction is "backward".
trace:
If TRUE, information is printed during the running of step.glm. This is an encouraging choice in general, since step.glm can take some time to compute either for large models or when called with an an extensive scope= argument. The information printed includes the anova tables computed for the selection of each model, as well as a simple one line model summary for each selected and iterated model.
keep:
A filter function whose input is a fitted glm object and the associated "AIC" statistic, and whose output is arbitrary. Typically keep will select a subset of the components of the object and return them. The default is not to keep anything.
steps:
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.

VALUE:
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.

DETAILS:
After parsing the scope= argument, step.glm computes the model matrix corresponding to the upper scope. It then enters a loop, adding or deleting a term at a time. The term for deletion or addition is based on the output of drop1 and add1, a type of score test based on the current fit. Once a model is selected, it is iterated to convergence, and the loop continues. The iterations stop when no step decreases the AIC criterion, defined by AIC = Deviance +2*scale*df.resid.

SEE ALSO:
add1 , drop1 , glm , Kyphosis , Methods , step.glm .

EXAMPLES:
glm.object <- glm(Kyphosis ~ Age + Start + Number,
                  family = binomial, data = kyphosis)

step(glm.object) step(glm.object,list(upper = ~.^2, lower = ~ Age))