[R] backward stepwise model selection

Ben Bolker bbolker at gmail.com
Fri Oct 26 22:21:27 CEST 2012


Hui Du <Hui.Du <at> dataventures.com> writes:

> I know in R there is function named 'step', which does the
>  stepwise regression and choose the model by AIC.
> However, if I want to choose a model per this logic:
> 
> 1.       Run a full model  (linear regression, f = lm(y ~., data = ZZZ),
>    for example)
> 
> 2.       Pick up the variable with biggest p value, delete it from the module
and get a new regression model.
> 
> 3.      Repeat step 2 until all variables are significant in a model.
> 
> My question is that do you know if R has a function (like 'step') 
>  to do that or I must write it by myself?

  There is a fastbw function in the rms package that will do something
like this.  However, I'm now going to SHOUT AT YOU A LITTLE BIT (sorry).

  THERE ARE VERY, VERY FEW SITUATIONS WHERE STEPWISE REGRESSION BASED
ON P-VALUES MAKES SENSE.  IF YOU'RE PLANNING TO USE THIS IN A REAL
STATISTICAL SETTING, PLEASE GOOGLE "stepwise regression bad", READ
SOME OF THE ENSUING LINKS, AND REEVALUATE YOUR PLANS.

  We now return you to your regular programming, and remind you
that all advice from r-help comes with a 100% money-back guarantee ...

  Ben Bolker




More information about the R-help mailing list