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 upStepwise forward regression fails when model formula contains inline functions #8
Comments
|
> library(olsrr)
> library(caret)
> data("Sacramento")
> lm_fit2 <- lm(price ~ beds + baths + log(sqft), data = Sacramento)
> ols_step_forward(lm_fit2)
We are selecting variables based on p value...
1 variable(s) added....
1 variable(s) added...
No more variables satisfy the condition of penter: 0.3
Forward Selection Method
Candidate Terms:
1 . beds
2 . baths
3 . log(sqft)
-------------------------------------------------------------------------------
Selection Summary
-------------------------------------------------------------------------------
Variable Adj.
Step Entered R-Square R-Square C(p) AIC RMSE
-------------------------------------------------------------------------------
1 log(sqft) 0.568 0.567 52.6943 23833.1040 86242.3553
2 beds 0.591 0.590 2.9559 23784.5900 83981.7543
-------------------------------------------------------------------------------
# interaction variables
> lm_fit3 <- lm(mpg ~ disp + hp + wt + am * disp, data = mtcars)
> ols_step_forward(lm_fit3)
We are selecting variables based on p value...
1 variable(s) added....
1 variable(s) added...
1 variable(s) added...
1 variable(s) added...
1 variable(s) added...
Forward Selection Method
Candidate Terms:
1 . disp
2 . hp
3 . wt
4 . am
5 . disp:am
-------------------------------------------------------------------------
Selection Summary
-------------------------------------------------------------------------
Variable Adj.
Step Entered R-Square R-Square C(p) AIC RMSE
-------------------------------------------------------------------------
1 wt 0.753 0.745 15.7814 166.0294 3.0458
2 hp 0.827 0.815 4.6820 156.6523 2.5935
3 am 0.840 0.823 4.3607 156.1348 2.5375
4 disp:am 0.853 0.831 4.0081 155.3638 2.4747
5 disp 0.853 0.825 6.0000 157.3538 2.5213
------------------------------------------------------------------------- |
ols_step_forward()returns an error when the model formula contains inline functions or interaction variables.Session Info