Example arbitrary df:
Dates NY CA OH MA
2018-01-01 9073 4564 2342 5645
2018-01-02 2342 4565 3453 5675
2018-01-03 1234 7567 5345 6877
2018-01-04 1231 3545 3453 7686
2018-01-05 4512 4564 3453 6787
..... .... .... .... ....
I am trying to run a iterative stepwise regression on a df containing >300 variables. I set-up an easy dffor myself (illustrated above) to practice getting there.
Here is what I wish to achieve: 1) Stepwise regression 2) Remove coefficients >= specified value (choose any for testing, say .1) 3) Re-run stepwise regression 4) Repeat step 2 or stop if constraint specified not met (meaning, stop loop if all coefficients are within the specified value)
Here are the pieces I have thus far:
1) step(lm(NY~. -Dates, df))
2) names(coef(df))[which(coef(df)<=.2)]
So 1 accomplishes running stepwise regression and 2 accomplishes naming the coefficients that are less than or equal to a specified value, say 0.2. How do I combine the code to remove those values from the step 1 regression and re-apply step wise regression without the variables, and continue this process until all variables comply within a specified range?
Thank you,