lmSubsets: All-subsets regression

Description Usage Arguments Details Value See Also Examples

Description

All-variable-subsets selection in ordinary linear regression.

Usage

1
2
3
4
5
6
lmSubsets(formula, ...)

## Default S3 method:
lmSubsets(formula, data, subset, weights, na.action,
          model = TRUE, x = FALSE, y = FALSE, contrasts = NULL,
          offset, ...)

Arguments

formula, data, subset, weights, na.action, model, x, y, contrasts, offset

standard formula interface

...

fowarded to lmSubsets_fit()

Details

The lmSubsets() generic provides various methods to conveniently specify the regressor and response variables. The standard formula interface (see lm()) can be used, or the model information can be extracted from an already fitted "lm" object. The model matrix and response can also be passed in directly.

After processing of the arguments, the call is forwarded to lmSubsets_fit().

Value

"lmSubsets"—a list containing the components returned by lmSubsets_fit()

Further components include call, na.action, weights, offset, contrasts, xlevels, terms, mf, x, and y. See lm() for more information.

See Also

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
## load data
data("AirPollution", package = "lmSubsets")


###################
##  basic usage  ##
###################

## canonical example: fit all subsets
lm_all <- lmSubsets(mortality ~ ., data = AirPollution, nbest = 5)
lm_all

## plot RSS and BIC
plot(lm_all)

## summary statistics
summary(lm_all)


############################
##  forced in-/exclusion  ##
############################

lm_force <- lmSubsets(lm_all, include = c("nox", "so2"),
                      exclude = "whitecollar")
lm_force

Example output

Call:
  lmSubsets(formula = mortality ~ ., data = AirPollution, nbest = 5)

Deviance:
  [best, size (tolerance)] = RSS
      2 (0)    3 (0)     4 (0)    5 (0)    6 (0)    7 (0)    8 (0)    9 (0)   
  1st 133694.5  99841.07 82388.53 69154.11 64633.79 60538.76 58385.72 57379.21
  2nd 168695.5 103859.31 83335.14 72250.33 65659.86 62288.70 58870.48 57617.43
  3rd 169041.4 109202.60 85241.98 74666.42 66554.64 62953.77 60057.48 57748.66
  4th 186715.9 112259.15 88542.69 76230.34 66837.27 63007.12 60422.51 57948.25
  5th 186896.2 115541.19 88919.66 76276.41 67621.51 63205.56 60465.10 58093.85
      10 (0)   11 (0)   12 (0)   13 (0)   14 (0)   15 (0)   16 (0)  
  1st 55358.05 54221.58 53921.82 53712.66 53696.00 53683.31 53680.02
  2nd 56185.55 54718.93 54146.37 53874.74 53696.65 53690.20         
  3rd 56550.95 55260.67 54186.59 53900.78 53709.86 53695.48         
  4th 56818.31 55298.82 54217.60 53917.84 53846.53 53845.54         
  5th 56896.70 55343.71 54219.26 54112.97 53872.20 54097.09         

Subset:
  [variable, best] = size
                1st       2nd          3rd              4th            5th       
  +(Intercept)  2-16      2-15         2-15             2-15           2-15      
  precipitation 5-16      4,6-15       2,6-15           6-15           5,7-15    
  temperature1  4-16      3,5-15       5-15             4-15           6-15      
  temperature7  7-16      6,8-15       8-15             7-15           8-15      
  age           9-16      11-15        11-15            3,10-15        6,8,11-15 
  household     8-16      7,9-15       5,10-15          9-15           9,11-15   
  education     3-4,6-16  2,5,7-15     4-5,7,9-15       5,8-15         4-15      
  housing       13-16     12,14-15     8,14-15          2,8            11,13,15  
  population    11-16     8-10,12-15   6-9,12-15        5,7,10,12-15   10,12-15  
  noncauc       2-16      3-15         3-15             3-15           3-15      
  whitecollar   14-16     15                            6,11-13,15     3,14-15   
  income        16        13,15        11,14-15         14-15          4,12,14-15
  hydrocarbon   10-16     10-15        9-15             9,11-15        9-15      
  nox           10-16     10-15        9-15             9,11-15        10-15     
  so2           5-9,12-16 4-9,11,13-15 3-4,6-8,10,13-15 4,6-8,10,13-15 2,5-10,14 
  humidity      15-16     14           12-13,15         14-15          7,13,15   

Call:
  lmSubsets(formula = mortality ~ ., data = AirPollution, nbest = 5)

Statistics:
   SIZE BEST sigma    R2        R2adj     pval       Cp        AIC      BIC     
    2   1    48.01123 0.4144106 0.4043142 2.8849e-08 53.585642 638.8107 645.0938
        2    53.93092 0.2611043 0.2483647 3.0221e-05 82.274971 652.7630 659.0460
        3    53.98617 0.2595895 0.2468238 3.2154e-05 82.558453 652.8859 659.1689
        4    56.73835 0.1821741 0.1680736 0.00067180 97.045770 658.8526 665.1356
        5    56.76573 0.1813844 0.1672704 0.00069216 97.193535 658.9105 665.1935
    3   1    41.85209 0.5626906 0.5473464 5.7874e-11 27.836910 623.2920 631.6694
        2    42.68598 0.5450905 0.5291288 1.7818e-10 31.130547 625.6595 634.0369
        3    43.77025 0.5216866 0.5049037 7.4440e-10 35.510292 628.6696 637.0469
        4    44.37859 0.5082988 0.4910461 1.6349e-09 38.015663 630.3259 638.7032
        5    45.02264 0.4939233 0.4761662 3.7168e-09 40.705855 632.0549 640.4323
    4   1    38.35653 0.6391337 0.6198016 1.9699e-12 15.531554 613.7640 624.2358
        2    38.57626 0.6349875 0.6154333 2.7041e-12 16.307465 614.4495 624.9212
        3    39.01510 0.6266355 0.6066338 5.0630e-12 17.870447 615.8069 626.2786
        4    39.76329 0.6121782 0.5914020 1.4508e-11 20.575948 618.0864 628.5581
        5    39.84785 0.6105270 0.5896624 1.6319e-11 20.884938 618.3413 628.8130
    5   1    35.45910 0.6971012 0.6750722 1.0975e-13  6.683675 605.2575 617.8236
        2    36.24421 0.6835396 0.6605243 3.5924e-13  9.221560 607.8855 620.4516
        3    36.84523 0.6729570 0.6491721 8.7460e-13 11.201957 609.8591 622.4252
        4    37.22910 0.6661069 0.6418238 1.5317e-12 12.483863 611.1028 623.6689
        5    37.24035 0.6659052 0.6416073 1.5569e-12 12.521620 611.1391 623.7052
    6   1    34.59656 0.7169005 0.6906875 1.1157e-13  4.978493 603.2015 617.8619
        2    34.87009 0.7124062 0.6857771 1.6918e-13  5.819540 604.1465 618.8069
        3    35.10688 0.7084870 0.6814951 2.4190e-13  6.552961 604.9587 619.6191
        4    35.18135 0.7072491 0.6801425 2.7055e-13  6.784624 605.2129 619.8733
        5    35.38715 0.7038141 0.6763895 3.6815e-13  7.427446 605.9128 620.5732
    7   1    33.79705 0.7348369 0.7048185 1.1482e-13  3.621912 601.2743 618.0290
        2    34.28204 0.7271721 0.6962859 2.3951e-13  5.056290 602.9841 619.7388
        3    34.46458 0.7242590 0.6930431 3.1495e-13  5.601433 603.6213 620.3761
        4    34.47918 0.7240254 0.6927829 3.2190e-13  5.645161 603.6721 620.4269
        5    34.53343 0.7231562 0.6918154 3.4908e-13  5.807818 603.8608 620.6156
    8   1    33.50824 0.7442674 0.7098418 2.4093e-13  3.857124 601.1015 619.9506
        2    33.64706 0.7421441 0.7074327 2.9669e-13  4.254470 601.5977 620.4468
        3    33.98458 0.7369449 0.7015337 4.9030e-13  5.227424 602.7954 621.6445
        4    34.08770 0.7353461 0.6997196 5.7101e-13  5.526625 603.1590 622.0081
        5    34.09971 0.7351595 0.6995079 5.8122e-13  5.561539 603.2012 622.0504
    9   1    33.54225 0.7486759 0.7092525 7.6686e-13  5.032120 602.0582 623.0016
        2    33.61181 0.7476325 0.7080454 8.4893e-13  5.227381 602.3068 623.2502
        3    33.65006 0.7470577 0.7073805 8.9767e-13  5.334944 602.4433 623.3867
        4    33.70816 0.7461835 0.7063692 9.7696e-13  5.498543 602.6503 623.5937
        5    33.75048 0.7455457 0.7056313 1.0390e-12  5.617893 602.8009 623.7443
   10   1    33.27403 0.7575287 0.7138839 1.4806e-12  5.375433 601.9066 624.9444
        2    33.52180 0.7539042 0.7096070 2.1117e-12  6.053710 602.7968 625.8346
        3    33.63063 0.7523037 0.7077184 2.4657e-12  6.353221 603.1858 626.2236
        4    33.71003 0.7511327 0.7063366 2.7600e-12  6.572369 603.4688 626.5066
        5    33.73328 0.7507893 0.7059314 2.8525e-12  6.636619 603.5515 626.5893
   11   1    33.26504 0.7625065 0.7140385 3.9595e-12  6.443899 602.6620 627.7941
        2    33.41725 0.7603281 0.7114155 4.8987e-12  6.851561 603.2098 628.3420
        3    33.58227 0.7579552 0.7085584 6.1626e-12  7.295611 603.8010 628.9331
        4    33.59386 0.7577881 0.7083572 6.2625e-12  7.326881 603.8424 628.9745
        5    33.60749 0.7575915 0.7081204 6.3819e-12  7.363676 603.8910 629.0232
   12   1    33.51673 0.7638195 0.7096948 1.4379e-11  8.198194 604.3294 631.5559
        2    33.58645 0.7628359 0.7084858 1.5800e-11  8.382254 604.5787 631.8052
        3    33.59892 0.7626598 0.7082693 1.6068e-11  8.415219 604.6233 631.8498
        4    33.60853 0.7625239 0.7081023 1.6278e-11  8.440642 604.6576 631.8841
        5    33.60905 0.7625167 0.7080934 1.6289e-11  8.442000 604.6594 631.8859
   13   1    33.80566 0.7647356 0.7046681 5.1381e-11 10.026756 606.0962 635.4170
        2    33.85663 0.7640257 0.7037769 5.4909e-11 10.159607 606.2770 635.5978
        3    33.86481 0.7639116 0.7036338 5.5497e-11 10.180949 606.3060 635.6268
        4    33.87017 0.7638369 0.7035399 5.5886e-11 10.194933 606.3250 635.6458
        5    33.93140 0.7629822 0.7024671 6.0516e-11 10.354873 606.5417 635.8625
   14   1    34.16584 0.7648086 0.6983414 1.8846e-10 12.013101 608.0776 639.4928
        2    34.16604 0.7648057 0.6983378 1.8850e-10 12.013627 608.0783 639.4935
        3    34.17025 0.7647479 0.6982636 1.8950e-10 12.024458 608.0931 639.5082
        4    34.21369 0.7641492 0.6974958 2.0009e-10 12.136485 608.2455 639.6607
        5    34.22185 0.7640368 0.6973515 2.0214e-10 12.157525 608.2741 639.6893
   15   1    34.53929 0.7648641 0.6917108 6.5757e-10 14.002698 610.0634 643.5729
        2    34.54150 0.7648340 0.6916712 6.5932e-10 14.008341 610.0711 643.5806
        3    34.54320 0.7648108 0.6916409 6.6067e-10 14.012672 610.0770 643.5865
        4    34.59144 0.7641536 0.6907792 7.0007e-10 14.135667 610.2444 643.7540
        5    34.67214 0.7630518 0.6893346 7.7116e-10 14.341858 610.5241 644.0336
   16   1    34.92851 0.7648786 0.6847235 2.1933e-09 16.000000 612.0597 647.6636
Call:
  lmSubsets(formula = lm_all, include = c("nox", "so2"), exclude = "whitecollar")

Deviance:
  [best, size (tolerance)] = RSS
      4 (0)   5 (0)    6 (0)    7 (0)   8 (0)    9 (0)    10 (0)   11 (0)  
  1st 95395.1 80822.35 68771.08 64068.5 60537.85 58287.14 56550.95 54718.93
      12 (0)   13 (0)   14 (0)   15 (0)  
  1st 53921.82 53712.66 53696.65 53695.48

Subset:
  [variable, best] = size
                1st   
  +(Intercept)  4-15  
  precipitation 6-15  
  temperature1  6-15  
  temperature7  8-15  
  age           11-15 
  household     9-15  
  education     5,7-15
  housing       13-15 
  population    12-15 
  noncauc       4-15  
  -whitecollar        
  income        15    
  hydrocarbon   10-15 
  +nox          4-15  
  +so2          4-15  
  humidity      14-15 

lmSubsets documentation built on Feb. 8, 2021, 1:06 a.m.