regression subset selection

regression subset selection [R logo]

Help pages for package `leaps' version 2.7

leaps | all-subsets regressiom
leaps.backward | Internal functions for leaps(), subsets()
leaps.exhaustive | Internal functions for leaps(), subsets()
leaps.forward | Internal functions for leaps(), subsets()
leaps.seqrep | Internal functions for leaps(), subsets()
leaps.setup | Internal functions for leaps(), subsets()
plot.regsubsets | Graphical table of best subsets
print.regsubsets | functions for model selection
print.summary.regsubsets | functions for model selection
regsubsets | functions for model selection
summary.regsubsets | functions for model selection


all-subsets regressiom

Description

leaps() performs an exhaustive search for the best subsets of the variables in x for predicting y in linear regression, using an efficient branch-and-bound algorithm. It is a compatibility wrapper for regsubsets does the same thing better.

Usage

leaps(x=, y=, wt=rep(1, NROW(x)), int=TRUE, method=c("Cp", "adjr2", "r2"), nbest=10, names=NULL, df=NROW(x), strictly.compatible=TRUE)

Arguments

x | A matrix of predictors
y | A response vector
wt | Optional weight vector
int | Add an intercept to the model
method | Calculate Cp, adjusted R-squared or R-squared
nbest | Number of subsets of each size to report
names | vector of names for columns of x
df | Total degrees of freedom to use instead of nrow(x) in calculating Cp and adjusted R-squared
strictly.compatible | Implement misfeatures of leaps() in S

Value

A list with components

which | logical matrix. Each row can be used to select the columns of x in the respective model
size | Number of variables, including intercept if any, in the model
cp | or adjr2 or r2 is the value of the chosen model selectionstatistic for each model
label | vector of names for the columns of x

Note

With strictly.compatible=T the function will stop with an error if x is not of full rank or if it has more than 31 columns. It will ignore the column names of x even if names==NULL and will replace them with "0" to "9", "A" to "Z".

References

Alan Miller "Subset Selection in Regression" Chapman & Hall

See Also

regsubsets, regsubsets.formula, regsubsets.default

Examples

x<-matrix(rnorm(100),ncol=4)
y<-rnorm(25)
leaps(x,y)
[Package leaps version 2.7 Index]


Internal functions for leaps(), subsets()

leaps.setup(leaps) R Documentation

Internal functions for leaps() subsets()

Description

These functions are used internally by regsubsets and leaps. They are wrappers for Fortran routines that construct and manipulate a QR decomposition.

Usage

leaps.setup(x,y,wt=rep(1,length(y)),force.in=NULL,force.out=NULL,intercept=TRUE,nvmax=8,nbest=1,warn.dep=TRUE)
leaps.seqrep(leaps.obj)
leaps.exhaustive(leaps.obj,really.big=FALSE)
leaps.backward(leaps.obj)
leaps.forward(leaps.obj)

Arguments

x | A matrix of predictors
y | A response vector
wt | Optional weight vector
intercept | Add an intercept to the model
force.in | vector indicating variable that must be in the model
force.out | vector indicating variable that must not be in the model
nbest | Number of subsets of each size to report
nvmax | largest subset size to examine
warn.dep | warn if x is not of full rank
leaps.obj | An object of class leaps as produced by leaps.setup
really.big | required before R gets sent off on a long uninterruptible computation

See Also

regsubsets, leaps

[Package leaps version 2.7 Index]


Graphical table of best subsets

Description

Plots a table of models showing which variables are in each model. The models are ordered by the specified model selection statistic. This plot is particularly useful when there are more than ten or so models and the simple table produced by summary.regsubsets is too big to read.

Usage

## S3 method for class 'regsubsets':
plot(x, labels=obj$xnames, main=NULL, scale=c("bic", "Cp", "adjr2", "r2"), col=gray(seq(0, 0.9, length = 10)),...)

Arguments

x | regsubsets object
labels | variable names
main | title for plot
scale | which summary statistic to use for ordering plots
col | Colors: the last color should be close to but distinct from white
... | other arguments

Value

None

Author(s)

Thomas Lumley, based on a concept by Merlise Clyde

See Also

regsubsets,summary.regsubsets

Examples

data(swiss)
a<-regsubsets(Fertility~.,nbest=3,data=swiss)
par(mfrow=c(1,2))
plot(a)
plot(a,scale="r2")
[Package leaps version 2.7 Index]


functions for model selection

Description

Generic function for regression subset selection with methods for formula and matrix arguments.

Usage

regsubsets(x=, ...)

## S3 method for class 'formula':
regsubsets(x=, data=, weights=NULL, nbest=1, nvmax=8, force.in=NULL, force.out=NULL, intercept=TRUE, method=c("exhaustive", "backward", "forward", "seqrep"), really.big=FALSE,...)

## Default S3 method:
regsubsets(x=, y=, weights=rep(1, length(y)), nbest=1, nvmax=8,
force.in=NULL, force.out=NULL, intercept=TRUE, method=c("exhaustive",
"backward", "forward", "seqrep"), really.big=FALSE,...)

## S3 method for class 'regsubsets':
summary(object,all.best=TRUE,matrix=TRUE,matrix.logical=FALSE,df=NULL,...)

Arguments

x | design matrix or model formula for full model
data | Optional data frame
y | response vector
weights | weight vector
nbest | number of subsets of each size to record
nvmax | maximum size of subsets to examine
force.in | index to columns of design matrix that should be in all models
force.out | index to columns of design matrix that should be in no models
intercept | Add an intercept?
method | Use exhaustive search, forward selection, backward selection or sequential replacement to search.
really.big | Must be TRUE to perform exhaustive search on more than 50 variables.
object | regsubsets object
all.best | Show all the best subsets or just one of each size
matrix | Show a matrix of the variables in each model or just summary statistics
matrix.logical | With matrix=TRUE, the matrix is logical TRUE/FALSE or string "*"/code{" "}
df | Specify a number of degrees of freedom for the summary statistics. The default is n-1
... | Other arguments for future methods

Value

An object of class "regsubsets" containing no user-serviceable parts. It is designed to be processed by summary.regsubsets.

Note

This function improves on leaps in several ways. The design matrix need not be of full rank. The ability to restrict nvmax speeds up exhaustive searches considerably. There is no hard-coded limit to the number of variables.

See Also

leaps

Examples

data(swiss)
a<-regsubsets(as.matrix(swiss[,-1]),swiss[,1])
summary(a)
b<-regsubsets(Fertility~.,data=swiss)
summary(a)
[Package leaps version 2.7 Index]