bestlm: Subsets regression

Description Usage Arguments Details Value Note See Also Examples

View source: R/bestlm.R

Description

bestlm performs an exhaustive search for the best subsets of the variables in ind for predicting dip in linear regression.

Usage

1
2
3
4
5
 bestlm (dip, ind, kmax=4, nbest=3)
 ## S3 method for class 'bestlm'
 print(x, ...)
 ## S3 method for class 'bestlm'
 summary(object, ...)

Arguments

x

object of class bestlm, output of function bestlm

object

object of class bestlm, output of function bestlm

dip

vector n x 1 of dependent variable to be predicted

ind

matrix n x K of the K independent variables (candidate predictors)

kmax

maximum size (number of regressors) to report

nbest

number of subsets of each size to report

...

other arguments

Details

This function has been obtained using the function leaps of the R package leaps. It is based on the Alan Miller's FORTRAN routines.

Warning: the function will stop with an error if ind is not of full rank or if it has more than 31 columns.

Value

bestlm returns the following values:

subselect matrix (kmax*nbest)x(ncol(ind)) with the sets of chosen linear models, ordered in function of the adjusted coefficient of determination (R2adj);

R2adj the ordered adjusted coefficient of determination;

Note

For information on the package and the Author, and for all the references, see nsRFA.

See Also

lm, REGRDIAGNOSTICS.

Examples

1
2
3
4
5
6
data(hydroSIMN)

bestlm(parameters[,"Dm"], parameters[,-c(1:2)])

regr <- lm(Dm ~ Am + S2000 + NORD, parameters); regr
summary(regr)

Example output

                    model     R2adj
1  Am + S2000 + NORD + IT 0.8868897
2    Am + S2000 + Rc + IT 0.8852187
3         Am + S2000 + IT 0.8851092
4    Am + S2000 + IT + IB 0.8836972
5         Am + S2000 + IB 0.8793968
6       Am + S2000 + NORD 0.8775756
7              Am + S2000 0.8761521
8                 Am + Hm 0.8588129
9                 Hm + IB 0.8549638
10                     IT 0.8467383
11                     IB 0.6094562
12                     Am 0.5323001

Call:
lm(formula = Dm ~ Am + S2000 + NORD, data = parameters)

Coefficients:
(Intercept)           Am        S2000         NORD  
   -636.519        1.126        6.571       31.908  


Call:
lm(formula = Dm ~ Am + S2000 + NORD, data = parameters)

Residuals:
    Min      1Q  Median      3Q     Max 
-251.58  -58.27   12.66   68.04  244.59 

Coefficients:
              Estimate Std. Error t value Pr(>|t|)    
(Intercept) -636.51933  105.22178  -6.049 3.10e-07 ***
Am             1.12647    0.06887  16.357  < 2e-16 ***
S2000          6.57056    0.58598  11.213 2.39e-14 ***
NORD          31.90839   25.95279   1.229    0.226    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 112.3 on 43 degrees of freedom
Multiple R-squared:  0.8856,	Adjusted R-squared:  0.8776 
F-statistic: 110.9 on 3 and 43 DF,  p-value: < 2.2e-16

nsRFA documentation built on May 29, 2017, 1:02 p.m.