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 backward regression fails when model formula contains inline functions or interaction variables #7
Comments
|
> library(olsrr)
> library(caret)
> data("Sacramento")
> lm_fit2 <- lm(price ~ beds + baths + log(sqft), data = Sacramento)
> ols_step_backward(lm_fit2)
We are eliminating variables based on p value...
No more variables satisfy the condition of prem: 0.3
Backward Elimination Method
Candidate Terms:
1 . beds
2 . baths
3 . log(sqft)
----------------------------------------------------------------------------
Elimination Summary
----------------------------------------------------------------------------
Variable Adj.
Step Removed R-Square R-Square C(p) AIC RMSE
----------------------------------------------------------------------------
1 baths 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_backward(lm_fit3)
We are eliminating variables based on p value...
No more variables satisfy the condition of prem: 0.3
Backward Elimination Method
Candidate Terms:
1 . disp
2 . hp
3 . wt
4 . am
5 . disp:am
------------------------------------------------------------------------
Elimination Summary
------------------------------------------------------------------------
Variable Adj.
Step Removed R-Square R-Square C(p) AIC RMSE
------------------------------------------------------------------------
1 disp 0.853 0.831 4.0081 155.3638 2.4747
------------------------------------------------------------------------ |
ols_step_backward()returns an error when the model formula contains inline functions or interaction variables.Session Info