Hi, there,

My appologize if someone ask the same question before. I searched the
mailing list and found one similar post, but not what i want.

The problem for me is, I use the step( glm()....) to do naive forward
selection for logistic regression.  My code is functional
in the open environment. But if I wrap it up as a function, then R keeps
saying "object 'a' not found". Actually,  data frame
"a" is inside the function.

I did some search online. i guess the reason may be R did not keep the data
in glm() output after building the model but not sure.
Can anyone please tell me how to work around this problem?

Thanks a lot in advance.

I am using R 2.9.0. Here is the sample code:

#------------
naivelr<-function(x,y){
:
:
:

a<-data.frame(x)

form<-paste("y~1+",paste(grep("X.*",names(a),value=T),collapse="+"),sep="")

if(is.null(force.in)!=T){
lowmo<-paste("y~1+",paste(grep("X.*",names(a)[force.in],value=T),collapse="+"),sep="")

} else
{lowmo<-"y~1"}

lower1<-glm(lowmo,family="binomial",data=data.frame(a,y))
upper1<-glm(form,family="binomial",data=data.frame(a,y))


stepout<-step(lower1,scope=list(lower=lower1,upper=upper1),direction="forward",k=0,trace=100)
# here is the error:Start:
#AIC=689.62
#y ~ 1
#Error in data.frame(a, y) : object 'a' not found---but "a" is there!
:
:
:
}




 Sincerely

samer yuan

	[[alternative HTML version deleted]]


