[R] forward stepwise selection

Simon Bond bond at graylab.ac.uk
Wed Jun 7 10:58:57 CEST 2000


Dear R-Help, 

My problem/bug came to light,when fitting a linear model using stepwise
selection. I'd started  with the straightfoward command

step(lm(y~., dataset))

This worked fine, but because this starts with  all the possible
explanatory variables, it results in a model with too many explanatory
variables. Hence I wanted to start with just a constant and do forward
selection, to get a new starting model for full stepwise selection again.
But R (version 0.99.0) doesn't like this.

> step(lm(ANB.DIFF~.,tink4),trace=0)

Call:
lm(formula = ANB.DIFF ~ SEX + AGE.YRS + OJS + S.AR1 + CD.GO1 +     CD.GN1 +
AR.GN1 + UAFH1 + UPFH1 + LPFH1 + AFP1 + PFP1 + OJ1 +     SNA1 + SNB1 +
SN.POG1, data = tink4)

Coefficients:
(Intercept)      SEXmale      AGE.YRS          OJS        S.AR1  
   -0.05001      0.47100      0.11148     -0.10458      0.11228  
     CD.GO1       CD.GN1       AR.GN1        UAFH1        UPFH1  
    0.28847     -0.38802      0.25388      0.13399     -0.31484  
      LPFH1         AFP1         PFP1          OJ1         SNA1  
   -0.17471     -5.11152      2.73038      0.21039      0.26088  
       SNB1      SN.POG1  
   -0.74297      0.56201  

> fmla
~1 + SEX + AGE.YRS + OJS + S.N1 + S.AR1 + B.N1 + CD.GO1 + CD.GN1 + 
    GO.GN1 + AR.GN1 + VRP.POG1 + UAFH1 + LAFH1 + UPFH1 + LPFH1 + 
    AFP1 + PFP1 + OB1 + OJ1 + SNA1 + SNB1 + SN.POG1 + MX.MN1 + 
    SN.MN1 + LAFH.P1 + LPFH.P1
>
step(lm(ANB.DIFF~1,tink4),scope=list(lower=~1,upper=fmla),direction="forward")
Start:  AIC= 25.35 
 ANB.DIFF ~ 1 

Error in lm.fit(X, y) : incompatible dimensions
> 



I've narrowed it down to the command add1(), which uses lm.fit(), but the
way add1() constructs X and y, is undecipherable. Any advice would be much
appreciated.



Simon Bond.


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list