rsquaredacademy / olsrr

Tools for developing OLS regression models
https://olsrr.rsquaredacademy.com/
Other
102 stars 22 forks source link

Feature request: max model order for `ols_step_all_possible` #202

Closed tikuma-lsuhsc closed 1 year ago

tikuma-lsuhsc commented 1 year ago

Would it be possible to add an optional argument to limit the maximum subset order?

As we all know, the number of combinations increases very fast while we may not need as high of a model order (or care to know about high-order models). Apologize if I'm off the mark here (I'm neither a statistician nor R user, rather signal processing engineer using R through Python rpy2).

Thanks, Kesh

aravindhebbali commented 1 year ago

Thanks for the suggestion. If I understand correctly, the user should be able to limit the number of predictors to be used while generating all possible combinations from amongst the predictors specified in the model.

library(olsrr)
#> 
#> Attaching package: 'olsrr'
#> The following object is masked from 'package:datasets':
#> 
#>     rivers
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

Created on 2022-11-02 by the reprex package (v0.3.0)

tikuma-lsuhsc commented 1 year ago

Yes, that's exactly what I have in my mind!