Learn R Programming

smooth (version 1.9.0)

stepwise: Stepwise selection of regressors

Description

Function selects variables that give linear regression with the lowest information criteria. The selection is done stepwise (forward) based on partial correlations. This should be a simpler and faster implementation than step() function from `stats' package.

Usage

stepwise(data, ic = c("AIC", "AICc", "BIC"), silent = TRUE, df = NULL)

Arguments

data
Data frame containing dependant variable in the first column and the others in the rest.
ic
Information criterion to use.
silent
If silent=FALSE, then nothing is silent, everything is printed out. silent=TRUE means that nothing is produced.
df
Number of degrees of freedom to add (should be used if stepwise is used on residuals).

Value

Function returns model - the final model of the class "lm".

Details

The algorithm uses lm() to fit different models and cor() to select the next regressor in the sequence.

See Also

step, xregExpander

Examples

Run this code

xreg <- cbind(rnorm(100,10,3),rnorm(100,50,5))
xreg <- cbind(100+0.5*xreg[,1]-0.75*xreg[,2]+rnorm(100,0,3),xreg)

stepwise(xreg)

Run the code above in your browser using DataLab