Skip to contents

Fits all regressions involving one regressor, two regressors, three regressors, and so on. It tests all possible subsets of the set of potential independent variables.

Usage

ols_step_all_possible(model, ...)

# S3 method for default
ols_step_all_possible(model, max_order = NULL, ...)

# S3 method for ols_step_all_possible
plot(x, model = NA, print_plot = TRUE, ...)

Arguments

model

An object of class lm.

...

Other arguments.

max_order

Maximum subset order.

x

An object of class ols_step_all_possible.

print_plot

logical; if TRUE, prints the plot else returns a plot object.

Value

ols_step_all_possible returns an object of class "ols_step_all_possible". An object of class "ols_step_all_possible" is a data frame containing the following components:

mindex

model index

n

number of predictors

predictors

predictors in the model

rsquare

rsquare of the model

adjr

adjusted rsquare of the model

rmse

root mean squared error of the model

predrsq

predicted rsquare of the model

cp

mallow's Cp

aic

akaike information criteria

sbic

sawa bayesian information criteria

sbc

schwarz bayes information criteria

msep

estimated MSE of prediction, assuming multivariate normality

fpe

final prediction error

apc

amemiya prediction criteria

hsp

hocking's Sp

References

Mendenhall William and Sinsich Terry, 2012, A Second Course in Statistics Regression Analysis (7th edition). Prentice Hall

Examples

model <- lm(mpg ~ disp + hp, data = mtcars)
k <- ols_step_all_possible(model)
k
#>   Index N Predictors  R-Square Adj. R-Square Mallow's Cp
#> 1     1 1       disp 0.7183433     0.7089548   0.6751205
#> 2     2 1         hp 0.6024373     0.5891853   0.5096958
#> 3     3 2    disp hp 0.7482402     0.7308774   0.6945438

# plot
plot(k)



# maximum subset
model <- lm(mpg ~ disp + hp + drat + wt + qsec, data = mtcars)
ols_step_all_possible(model, max_order = 3)
#>    Index N     Predictors  R-Square Adj. R-Square Mallow's Cp
#> 4      1 1             wt 0.7528328     0.7445939  0.70869536
#> 1      2 1           disp 0.7183433     0.7089548  0.67512054
#> 2      3 1             hp 0.6024373     0.5891853  0.50969578
#> 3      4 1           drat 0.4639952     0.4461283  0.39534988
#> 5      5 1           qsec 0.1752963     0.1478062  0.07541973
#> 11     6 2          hp wt 0.8267855     0.8148396  0.78108710
#> 15     7 2        wt qsec 0.8264161     0.8144448  0.77856272
#> 8      8 2        disp wt 0.7809306     0.7658223  0.72532105
#> 13     9 2        drat wt 0.7608970     0.7444071  0.70444676
#> 6     10 2        disp hp 0.7482402     0.7308774  0.69454380
#> 10    11 2        hp drat 0.7411716     0.7233214  0.67950230
#> 7     12 2      disp drat 0.7310094     0.7124583  0.68078942
#> 9     13 2      disp qsec 0.7215598     0.7023571  0.66395284
#> 12    14 2        hp qsec 0.6368769     0.6118339  0.52014395
#> 14    15 2      drat qsec 0.5921951     0.5640706  0.49351412
#> 25    16 3   drat wt qsec 0.8370214     0.8195594  0.77654413
#> 22    17 3     hp drat wt 0.8368791     0.8194018  0.78162798
#> 24    18 3     hp wt qsec 0.8347678     0.8170643  0.78199548
#> 17    19 3     disp hp wt 0.8268361     0.8082829  0.76789526
#> 21    20 3   disp wt qsec 0.8264170     0.8078189  0.76988533
#> 19    21 3   disp drat wt 0.7835315     0.7603385  0.71107192
#> 16    22 3   disp hp drat 0.7750131     0.7509073  0.71465331
#> 18    23 3   disp hp qsec 0.7541953     0.7278591  0.68301440
#> 23    24 3   hp drat qsec 0.7442512     0.7168495  0.66348166
#> 20    25 3 disp drat qsec 0.7412673     0.7135459  0.67099202