lmsel: Linear regression with variable selection

Description Usage Arguments Value Author(s) Examples

Description

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

Usage

1
2
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

1
2
3
4
5
6
7
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")

Example output

Loading required package: glmnet
Loading required package: Matrix
Loading required package: foreach
Loaded glmnet 2.0-16

Loading required package: elasticnet
Loading required package: lars
Loaded lars 1.2

Call:
lmsel.default(formula = lpsa ~ lcavol + lweight + age + lbph + 
    svi + lcp + gleason + pgg45, data = prostate, varsel = "lasso", 
    indices = as.numeric(prostate$train))

Coefficients:
(Intercept)      lcavol     lweight        lbph         svi       pgg45 
  -0.413675    0.512577    0.549081    0.072151    0.649625    0.002445 

Variable selection method: lasso 
Variables rejected: age lcp gleasonCall:
lmsel.default(formula = CompressiveStrength ~ ., data = concrete, 
    varsel = "step", criterion = "BIC")

Coefficients:
     (Intercept)           Cement BlastFurnaceSlag           FlyAsh 
        28.99298          0.10541          0.08647          0.06866 
           Water Superplasticizer              Age 
        -0.21809          0.24031          0.11349 

Variable selection method: step 
Variables rejected: FineAggregate CoarseAggregate

regsel documentation built on May 2, 2019, 1:44 p.m.

Related to lmsel in regsel...