Last data update: 2014.03.03

R: Linear regression with variable selection
lmselR Documentation

Linear regression with variable selection

Description

lmsel is used to fit linear models with optionally performing variable selection using stepwise regression, lasso or elastic net methods.

Usage

lmsel(formula, data=environment(), varsel=FALSE, criterion="AIC",
direction="backward", indices=NULL, train=0.3, lambda=1000)

Arguments

formula

an object of class "formula"; a symbolic description of the model to be fitted.

data

an optional data frame, list or environment containg the variables in the model. If not specified, the variables are taken from the current environment.

varsel

a method of variable selection to be used. The default is "FALSE". Available methods include: stepwise regression "step", LASSO "lasso", elastic net"enet".

criterion

when varsel="step", criterion allows to select a method of calculating statistic for model comparison. The default is "AIC". Less liberal, BIC penalty can be used by typing "BIC".

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".

indices

vector of 0 and 1 values indicating which observations are to be used as train and test when varsel="lasso" or "enet".

train

if indices=NULL, the function will randomly assign observations as train and test. train specifies what percentage of data will be used as train observations. Can take values from 0.1 to 0.9.

lambda

quadratic penalty parameter for elastic net. The default value is 1000.

Value

A "lmsel" object is returned, for which print, plot and summary methods can be used.

Author(s)

Michal Knut 1105406k@student.gla.ac.uk.

Examples

data(prostate)
set.seed(10)
lmsel(lpsa~lcavol+lweight+age+lbph+svi+lcp+gleason+pgg45, indices=as.numeric(prostate$train),
data=prostate, varsel="lasso")

data(concrete)
lmsel(CompressiveStrength~., data=concrete, varsel="step", criterion="BIC")

Results