Learn R Programming

selectiveInference (version 1.2.5)

fs: Forward stepwise regression

Description

This function implements forward stepwise regression, for use in the selectiveInference package

Usage

fs(x, y, maxsteps=2000, intercept=TRUE, normalize=TRUE, verbose=FALSE)

Arguments

x

Matrix of predictors (n by p)

y

Vector of outcomes (length n)

maxsteps

Maximum number of steps to take

intercept

Should an intercept be included on the model? Default is TRUE

normalize

Should the predictors be normalized? Default is TRUE. (Note: this argument has no real effect on model selection since forward stepwise is scale invariant already; however, it is included for completeness, and to match the interface for the lar function)

verbose

Print out progress along the way? Default is FALSE

Value

action

Vector of predictors in order of entry

sign

Signs of coefficients of predictors, upon entry

df

Degrees of freedom of each active model

beta

Matrix of regression coefficients for each model along the path, one column per model

completepath

Was the complete stepwise path computed?

bls

If completepath is TRUE, the full least squares coefficients

Gamma

Matrix that captures the polyhedral selection at each step

nk

Number of polyhedral constraints at each step in path

vreg

Matrix of linear contrasts that gives coefficients of variables to enter along the path

x

Matrix of predictors used

y

Vector of outcomes used

bx

Vector of column means of original x

by

Mean of original y

sx

Norm of each column of original x

intercept

Was an intercept included?

normalize

Were the predictors normalized?

call

The call to fs

Details

This function implements forward stepwise regression, adding the predictor at each step that maximizes the absolute correlation between the predictors---once orthogonalized with respect to the current model---and the residual. This entry criterion is standard, and is equivalent to choosing the variable that achieves the biggest drop in RSS at each step; it is used, e.g., by the step function in R. Note that, for example, the lars package implements a stepwise option (with type="step"), but uses a (mildly) different entry criterion, based on maximal absolute correlation between the original (non-orthogonalized) predictors and the residual.

See Also

fsInf, predict.fs,coef.fs, plot.fs

Examples

Run this code
# NOT RUN {
set.seed(33)
n = 50
p = 10
sigma = 1
x = matrix(rnorm(n*p),n,p)
beta = c(3,2,rep(0,p-2))
y = x%*%beta + sigma*rnorm(n)

# run forward stepwise, plot results
fsfit = fs(x,y)
plot(fsfit)

# compute sequential p-values and confidence intervals
# (sigma estimated from full model)
out = fsInf(fsfit)
out
# }

Run the code above in your browser using DataLab