# Saving each step of Backward selection in R

I'm trying to recreate Leo Breiman's work http://www.stat.washington.edu/courses/stat527/s13/readings/BreimanSpector_1992.pdf and I'm experiencing some major difficulties in R.

I've made it that far that I have a function producing random samples from multivariate normal distribution with zero mu vector and covariance matrix same as in the paper.

If I understand the paper correctly, I should make a random sample (checked), apply one of the 4 models H1-H4 to get the real values y (checked) and then apply LOOCV, K Fold, or Bootstrap to fit the data and compare the hat ys with the real ones. Though I'm not very experienced, I think I'm capable to construct all of this.

What I'm having major difficulties with is that I can't seem to find any fuction that would allow me to repeat the process in the paragraph above, store the result, and then repeat it again with -1 variables (the excluded variable can be excluded based on any criteria).

I've experimented with step(), stepAIC(), leaps(), regsubsets() and nothing gave me the slightest hint of what I need. However, there's a 100% chance I'm using them wrong. Can you please advise?

Thanks to everyone. Ondra

It's not clear what you mean by "store the result". Which result do you wish to store?

As far as refitting, R has a function update that will refit a model with changed inputs.

Alternatively you might looking for functions like drop1 (and add1).

Functions like leaps are designed to make their own way through many models, you seem to want to implement the individual stages of moving between adjacent models, and refitting.

• Well, I'd like to fit the model with let's say 40 variables, calculate Model Error, save the Model Error, drop the least significant explanatory variable, repeat. – Ondra Lepša Sep 16 '14 at 5:36
• I should take this chance to mention the repeated warnings here on CrossValidated against stepwise model selection. – Glen_b Sep 16 '14 at 6:59
• See here for a discussion of how to make step work on single-variable-at-a-time significance. See here for a list of problems with what you want to do. – Glen_b Sep 16 '14 at 7:09
• About the stepwise, I know, I've stumbled upon a couple of threads mentioning this; however, I'm struggling with basics. Once I get the model working, I might start experiencing with other methods as well. Now I just need any seemingly justifiable variable deletion technique to get the whole thing going. Nevertheless, I want to thank you for your help :) – Ondra Lepša Sep 16 '14 at 17:29
• I'm happy to help you learn how to do it. What remains unanswered? – Glen_b Sep 16 '14 at 21:08