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 upinline functions in formulas cause error #2
Comments
|
Thank you @topepo. Yes, currently the variable selection methods work only when the formula is straight forward i.e. without any variable transformation or inline functions (which is a shortcoming). We will work on it as suggested by you. |
|
We have changed the way > library(olsrr)
> library(caret)
> data("Sacramento")
> lm_fit1 <- lm(log(price) ~ . - city, data = Sacramento)
> stepw <- ols_stepwise(lm_fit1)
We are selecting variables based on p value...
1 variable(s) added....
1 variable(s) added...
1 variable(s) added...
1 variable(s) added...
No more variables to be added or removed.
> stepw
Stepwise Selection Method
Candidate Terms:
1 . zip
2 . beds
3 . baths
4 . sqft
5 . type
6 . latitude
7 . longitude
---------------------------------------------------------------------------------------
Stepwise Selection Summary
---------------------------------------------------------------------------------------
Added/ Adj.
Step Variable Removed R-Square R-Square C(p) AIC RMSE
---------------------------------------------------------------------------------------
1 sqft addition 0.533 0.533 478.8286 740.1894 0.3592
2 longitude addition 0.561 0.560 398.6749 686.1102 0.3493
3 latitude addition 0.562 0.561 395.5536 684.5000 0.3479
4 baths addition 0.564 0.562 393.1857 683.4099 0.3479
---------------------------------------------------------------------------------------
> lm_fit2 <- lm(price ~ beds + baths + log(sqft), data = Sacramento)
> stepw <- ols_stepwise(lm_fit2)
We are selecting variables based on p value...
1 variable(s) added....
1 variable(s) added...
No more variables to be added or removed.
> stepw
Stepwise Selection Method
Candidate Terms:
1 . beds
2 . baths
3 . log(sqft)
-------------------------------------------------------------------------------------------
Stepwise Selection Summary
-------------------------------------------------------------------------------------------
Added/ Adj.
Step Variable Removed R-Square R-Square C(p) AIC RMSE
-------------------------------------------------------------------------------------------
1 log(sqft) addition 0.568 0.567 52.6943 23833.1040 86242.3553
2 beds addition 0.591 0.590 2.9559 23784.5900 83981.7543
------------------------------------------------------------------------------------------- |
|
I am closing this issue for the time being. Might have to reopen it when we come across any model that uses natural splines |
It looks like there are errors if any inline functions are used on either side of the formula:
It looks like
reg_compgets fed a data frame or matrix of predictors fromols_regress. You might want to pass the formula throughmodel.frameor something to resolve any functions that are embedded. You might also want to look out for an inline likenssince it will create 2+ columns from the original variable (in case it messes up how d.f. are counted).