[R] Stepwise analysis with fixed variables

Marc Schwartz marc_schwartz at me.com
Wed Nov 21 17:08:05 CET 2012


On Nov 21, 2012, at 6:41 AM, Einat <einatgranot at gmail.com> wrote:

> These are my questions: 
> 
> 1. For example, if this is my code: 
> 
>> RegModel =
> lm(glucose~sex+BMI+height+weight+education+ses,weight=w_without_non_response)
>> summary(RegModel) 
>> step(RegModel, direction ="backward",scope=list(lower=?,upper=?)) 
> 
> and I want the sex and height variables to be fixed, but the rest of the
> variables to go into the backward analysis, how should I write the scope
> function?
> 
> 2.How can I add an alpha level to the step function as a criterion for the
> backward regression analysis?
> 
> Thank you :) 



First, I strongly suggest that you search on the problems associated with using stepwise regression and alternative approaches. This subject has been discussed ad infinitum on this list and is not a reasonable approach to covariate selection.

To your first question, which Uwe replied to and which I thought was pretty clear:

  scope = list(upper = ~ sex + BMI + height + weight + education + ses, 
               lower = ~ sex + height)

It is described in the Details section of ?step and there is an example of this in ?stepAIC in V&R's MASS package, which is a default part of R and is linked in the See Also section of ?step.

To your second question, you can't. It uses AIC and this has also been discussed frequently on this list. You might look at Frank's fastbw() function in his 'rms' package on CRAN.

Regards,

Marc Schwartz




More information about the R-help mailing list