[R] Step.glm() question

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Jan 18 00:29:26 CET 2006


There is no step.glm in R!

I suggest that you forget about step.glm, and start afresh with step in R 
(which is a cut-down version of MASS's stepAIC rather than emulating 
step.glm in S). In particular, it avoids many of the pitfalls of step.glm.

Please do study the posting guide, and tell us your R version and provide 
a reproducible example.  Without the latter it is almost impossible to 
pinpoint the error (if indeed there is one using the current version of 
R).

You are using many unnecessary as.formula calls that make your code hard 
to read.  z ~ x+y is a formula and needs no coercion.


On Tue, 17 Jan 2006, Smith, Phil wrote:

> Hi:
>
> I am using step.glm() as follows:
>
> form1 	<- 	as.formula(haspdata ~ 1)
> lg.mod1 	<- 	glm ( formula=form1, data=st.mtx,
> family=binomial , na.action=na.omit )
>
> upper		<-	as.formula( haspdata ~ (
> c5+childnm+educ1+incpov1+marital+msa+racekid+racemom+sex+shotcard )^2)
> lower		<-	as.formula(haspdata~1)
> lst		<-	list( upper=upper , lower=lower )
> form1a.step	<-	step(lg.mod1, scope=lst , trace=T ,
> direction="both" )
>
> I get the following error message in R:
>
> Error in factor.scope(ffac, list(add = fadd, drop = fdrop)) :
>        upper scope does not include model
>
> Because I am trying to migrate from Splus to R, I ran that same code in
> Splus and do not get an error.
>
> Could someone please tell me:
> 	1) what I'm doing wrong in R, and
> 	2) what the distinction between R and Splus is in this case.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list