step.regr: Choose a model in a Stepwise Algorithm

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Select a formula-based model

Usage

1
2
3
step.regr(object, scope = NULL, expand=FALSE, scale = 0,
  direction = c("both", "backward", "forward"), trace = FALSE, keep = NULL,
  steps = 1000, k = 2, ...)

Arguments

object

an object representing a model of an appropriate class. This is used as the initial model in the stepwise search.

scope

defines the range of models examined in the stepwise search. This should be either a single formula, or a list containing components 'upper' and 'lower', both formulae. See the details for how to specify the formulae and how they are used.

expand

logical. If TRUE and scope is not specified, all squared terms and interactions are used as upper scope (using terms2order) and the formula of the object as the lower.

scale

used in the definition of the AIC statistic for selecting the models, currently only for 'lm', 'aov' and 'glm' models. The default value, '0', indicates the scale should be estimated: see 'extractAIC'.

direction

the mode of stepwise search, can be one of '"both"', '"backward"', or '"forward"', with a default of '"both"'. If the 'scope' argument is missing the default for 'direction' is '"backward"'.

trace

if positive, information is printed during the running of 'step'. Larger values may give more detailed information.

keep

a filter function whose input is a fitted model 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.

k

the multiple of the number of degrees of freedom used for the penalty. Only k = 2 gives the genuine AIC, k = log(n) is sometimes referred to as BIC or SBC. k=4 usually leads to models with formally significant terms.

...

any additional arguments to 'extractAIC'.

Details

The set of models searched is determined by the 'scope' argument. The right-hand-side of its 'lower' component must be included in the model, and right-hand-side of the model is included in the 'upper' component. If 'scope' is a single formula, it specifies the 'upper' component, and the 'lower' model is empty. If 'scope' is missing, the initial model is used as the 'upper' model.

Models specified by 'scope' can be templates to update 'object' as used by 'update.formula'. So using '.' in a 'scope' formula means 'what is already there', with '.^2' indicating all interactions of existing terms.

Missing values lead to a reduced dataset: step.regr works on the dataset that includes all variables appearing in scope and then drops all lines containing missing values (by applying na.omit). The result is the model re-fitted to the dataset with only the variables used in the final model. This may lead to an increased number of rows. This differs from the behavior of step of package stats.

[from step of package stats:] There is a potential problem in using 'glm' fits with a variable 'scale', as in that case the deviance is not simply related to the maximized log-likelihood. The '"glm"' method for function 'extractAIC' makes the appropriate adjustment for a 'gaussian' family, but may need to be amended for other cases. (The 'binomial' and 'poisson' families have fixed 'scale' by default and do not correspond to a particular maximum-likelihood problem for variable 'scale'.)

Value

The selected model is returned, with up to two additional components. There is an

anova

steps taken in the search,

keep

if the keep= argument was supplied in the call.


The '"Resid. Dev"' column of the analysis of deviance table refers to a constant minus twice the maximized log likelihood: it will be a deviance only in cases where a saturated model is well-defined (thus excluding 'lm', 'aov' and 'survreg' fits, for example).

Author(s)

Werner A, Stahel

See Also

step in package stats, stepAIC in package MASS, add1.regr, drop1.regr

Examples

1
2
3
4
5
r.fit <- regr(Fertility ~ ., data = swiss)
r.step <- step.regr(r.fit)
r.step$anova
r.st2 <- step.regr(r.fit, k=8, trace=FALSE)
r.st2

regr documentation built on Oct. 22, 2019, 3:01 p.m.