gam
and
glm
.
step(object, scope, scale, direction, trace=T, keep, steps)
"both"
,
"backward"
,
or
"forward"
,
with a default of
"both"
.
If the
scope
argument is missing,
the default for
direction
is
"backward"
.
TRUE
,
information is printed during the running of
step
.
This is usually a good choice,
because
step()
can take some time
for large models.
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.
"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.
A series of models is generated sequentially,
where each model differs from its neighbors by a single term.
The
step
methods differ in the way
they construct this sequence:
both in the way the set of candidates are generated for each step,
and in the way the candidates are evaluated for selection.
Note: this function should not be used with logistic regression.
S scoping rules require that you take care when wrapping a
step
function in a function. (See the chapter "Data Management" in the Programmer's Guide
or "S-Programming," Venables & Ripley, 2000 for more information.)
For example, the following code will not work,
even if you were to pass the
Data
object directly:
> Step.Funct <- function(){ > Data <- data.frame(matrix(rnorm(1000), ncol=20)); names(Data)[1] <- "Return" > LongRegr <- lm(Return~.,data=Data,na.action=na.exclude,singular.ok=T) > LongStep <- step(LongRegr, direction="both") > } > Step.Funct()
Step.Funct
work, you can assign the
data to frame 1, which lasts for the duration of the top level expression.
For example:
> Step.Funct <- function(){ > Data <- data.frame(matrix(rnorm(1000), ncol=20)) > names(Data)[1] <- "Return" > assign("..Step.Funct.Data", Data, frame=1) > LongRegr <- lm(Return~.,data=..Step.Funct.Data,na.action=na.exclude,singular.ok=T) > step(LongRegr, direction="both") > } > Step.Funct()(Note: Give it a unique name to avoid multiple functions assigning objects to frame 1 from colliding with each other.)
# Create a glm object: glm.object <- glm(skips ~ ., family=poisson, data=solder.balance) # Step through possible models quadratic interaction models step(glm.object, scope= ~ . ^2)