Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upbest subset regression fails when model formula contains inline functions or interaction variables #5
Comments
|
> library(olsrr)
> library(caret)
> data("Sacramento")
> lm_fit2 <- lm(price ~ beds + baths + log(sqft), data = Sacramento)
> ols_best_subset(lm_fit2)
Best Subsets Regression
-----------------------------------
Model Index Predictors
-----------------------------------
1 log(sqft)
2 beds log(sqft)
3 beds baths log(sqft)
-----------------------------------
Subsets Regression Summary
--------------------------------------------------------------------------------------------------------------------------------------------------------------
Adj. Pred
Model R-Square R-Square R-Square C(p) AIC SBIC SBC MSEP FPE HSP APC
--------------------------------------------------------------------------------------------------------------------------------------------------------------
1 0.5680 0.5670 0.5655 52.6943 23833.1040 21187.9990 23847.6160 7453739033.0154 7453704671.7157 8006182.8289 0.4340
2 0.5910 0.5900 0.5873 2.9559 23784.5900 21139.7082 23803.9393 7075719175.8852 7075637629.2594 7600145.5265 0.4120
3 0.5910 0.5900 0.5856 4.0000 23785.6305 21140.7635 23809.8172 7083688577.2837 7083541628.0341 7608705.5907 0.4124
--------------------------------------------------------------------------------------------------------------------------------------------------------------
AIC: Akaike Information Criteria
SBIC: Sawa's Bayesian Information Criteria
SBC: Schwarz Bayesian Criteria
MSEP: Estimated error of prediction, assuming multivariate normality
FPE: Final Prediction Error
HSP: Hocking's Sp
APC: Amemiya Prediction Criteria
# interaction variables
> lm_fit3 <- lm(mpg ~ disp + hp + wt + am * disp, data = mtcars)
> ols_best_subset(lm_fit3)
Best Subsets Regression
------------------------------------
Model Index Predictors
------------------------------------
1 wt
2 hp wt
3 hp wt am
4 hp wt am disp:am
5 disp hp wt am disp:am
------------------------------------
Subsets Regression Summary
-------------------------------------------------------------------------------------------------------------------------------
Adj. Pred
Model R-Square R-Square R-Square C(p) AIC SBIC SBC MSEP FPE HSP APC
-------------------------------------------------------------------------------------------------------------------------------
1 0.7530 0.7450 0.7087 15.7814 166.0294 77.0143 170.4266 9.8972 9.8572 0.3199 0.2801
2 0.8270 0.8150 0.7811 4.6820 156.6523 70.3199 162.5153 7.4314 7.3563 0.2402 0.2090
3 0.8400 0.8230 0.7879 4.3607 156.1348 72.9956 163.4635 7.3780 7.2438 0.2385 0.2059
4 0.8530 0.8310 0.7871 4.0081 155.3638 76.1548 164.1582 7.2864 7.0804 0.2355 0.2012
5 0.8530 0.8250 0.7704 6.0000 157.3538 81.8096 167.6140 7.8669 7.5490 0.2543 0.2145
-------------------------------------------------------------------------------------------------------------------------------
AIC: Akaike Information Criteria
SBIC: Sawa's Bayesian Information Criteria
SBC: Schwarz Bayesian Criteria
MSEP: Estimated error of prediction, assuming multivariate normality
FPE: Final Prediction Error
HSP: Hocking's Sp
APC: Amemiya Prediction Criteria
|
ols_best_subset()returns an error when the formula in the model contains inline functions or interaction variables.Session Info