[R] for parameter 'keep' in 'step'

Peter Ehlers ehlers at ucalgary.ca
Mon Nov 2 11:32:05 CET 2009


Wenxin Liu wrote:
> Hello Lady or Sir,
> 
> I want to do model selection with 'step' function. But there is a trouble to
> me.
> 
> For example, there are 5 independent variables, X0,X1,X2,X3 and X4; and 1
> dependent variable y.
> I want to run stepwise regression y ~ X0 + X1 + X2 + X3 + X4, and I want to
> keep X0 always in the
> model. Every time when I run command 'step' with 'keep', error information
> "could not find function 'keep' "
> is always shown.  Could you tell me how to use the parameter 'keep' in
> 'step' function?

You're obviously not defining a keep() function.
Use the scope= argument:

fm <- lm(y ~ X0 + X1 + X2 + X3 + X4)
sfm <- step(fm, scope = list(lower = ~ X0))

See an example in ?stepAIC in the MASS package or the
book referenced there.

  -Peter Ehlers

> 
> Thank you very much and best regards,
> 
> Wenxin Liu
> 2009.11.02
> -------------------------------------------------------------------------------------
> Wenxin Liu, Postdoc., Scientific staff
> State Plant Breeding Institute(720)
> University of Hohenheim
> 70593 Stuttgart, Germany
> 
> PhoneNo.: +49-(0)711-459-22670
> Telefax    : +49-(0)711-459-23841
> Email       : wenxin.liu at uni-hohenheim.de  (academic)
>         or     lwx.biostat at gmail.com             (personal)
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
>




More information about the R-help mailing list