[R] Function update problem

lun li lun_li at hotmail.com
Fri Feb 14 19:40:13 CET 2003


Dear Professor Ripley,

Thank you very much for your help.

I tested the idea by" form <- substitute(.~.+x[,i], list(i=i))", however the 
problem still is there.  In order to automate model selection, I prefer to 
use "update". My regression problem is to test significant predictors from  
several hundred candidates using forward regression by BIC criteria. For 
each loop, first to find one with maximum BIC and then to update "lm" to get 
a new model.  So, it is convenient to use"update" function. I would be 
grateful if you could still help.

In addition, I tried the way "update+add1" to my question.  But, new problem 
is " update.default(model, . ~ . + x) need an object with call component", 
help? The code is:

>model<-add1(model,.~.+form)
>model.new<-update(model,.~.+x)

With best regards,


Lun




>You can use substitute: something like (untested)
>
>for(i in 1:100){
>     form <- substitute(.~.+x[,i], list(i=i))
>     model <- update(model, form)
>     ## do something useful in here
>}
>and you do not need to update unchanged arguments!
>
>However, why are you rewriting add1.default, when there is add1.lm?
>
>On Thu, 13 Feb 2003, lun li wrote:
>
> > Dear all,
> >
> > I am trying an automatic model selection for a multiple linear 
>regression
> > using function lm and update. But, I meet a problem when using update. 
>The
> > problem is the function update can not update when variables as a 
>vector(for
> > example,x is a matrix with 100 regression variables). The code is as 
>below:
> >
> >   > model<-lm(y~x1,singular.ok=T,na.action=na.omit)
> >   > for(i in 1:100){
> >   > model<-update(model,.~.+x[,i],singular.ok=T,na.action=na.omit)}
> >
> > If the above code is represented as below, I can get the correct result.
> > However, I must use the loops.
> >
> > >model<-lm(y~x1,singular.ok=T,na.action=na.omit)
> > >model<-update(model,.~.+x[,1],singular.ok=T,na.action=na.omit)
> > >model<-update(model,.~.+x[,2],singular.ok=T,na.action=na.omit)
> >         ......
> > >model<-update(model,.~.+x[,100],singular.ok=T,na.action=na.omit)
>
>--
>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
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>http://www.stat.math.ethz.ch/mailman/listinfo/r-help
>
>----- End forwarded message -----
>
>
>
>Lun Li
>Department of Geology and Geophysics
>The University of Edinburgh
>Grant Institute                        Tel. +44(0)131 650 7339
>King's Buildings                       Fax. +44(0)131 668 3184
>West Mains Road			       E-mail:lun.li at glg.ed.ac.uk
>Edinburgh EH9 3JW
>UK




More information about the R-help mailing list