[R] Forward Stepwise regression with stepAIC and step

pfm401@lineone.net pfm401 at lineone.net
Thu May 8 11:15:03 CEST 2003


Dear all,

I cannot seem to get the R functions step or stepAIC to perform forward
or stepwise regression as I expect. I have enclosed the example data in
a dataframe at the end of this mail. Note rubbish is and rnorm(17) variable
which I have deliberately added to the data to test the stepwise procedure.

I have used 

wateruse.lm<-lm(waterusage~.,data=wateruse)   # Fit full model
wateruse.lm.back<-stepAIC(wateruse.lm,trace=FALSE)

in which rubbish is removed (calling wateruse.lm.back$anova gives      

Step         Df Deviance Resid. Df Resid. Dev      AIC
1           NA       NA        11   743720.8 193.6655
2 - rubbish  1 76.67448        12   743797.5 191.6673

However if I run

wateruse.lm.forward<-stepAIC(wateruse.lm,trace=FALSE,direction="forward")

wateruse.lm.forward$anova gives 

Stepwise Model Path 
Analysis of Deviance Table

Initial Model:
waterusage ~ avetemp + product + days + payroll + rubbish

Final Model:
waterusage ~ avetemp + product + days + payroll + rubbish


  Step Df Deviance Resid. Df Resid. Dev      AIC
1      NA       NA        11   743720.8 193.6655


In other words no forward procedure has been run (similar results apply
if I use direction="step")!!

What am I doing wrong?? Thanks in advance for any help.

Thanks, Paul.







> wateruse
   waterusage avetemp product days payroll    rubbish
1        3067    58.8    7107   21     129 -0.8393514
2        2828    65.2    6373   22     141 -0.8781807
3        2891    70.9    6796   22     153  1.1939278
4        2994    77.4    9208   20     166  0.2230589
5        3082    79.3   14792   25     193  1.7165612
6        3898    81.0   14564   23     189 -0.3810258
7        3502    71.9   11964   20     175 -0.1891337
8        3060    63.9   13526   23     186  1.1204482
9        3211    54.5   12656   20     190  2.6239803
10       3286    39.5   14119   20     187  0.9282131
11       3542    44.5   16691   22     195 -1.7371026
12       3125    43.6   14571   19     206 -0.1368085
13       3022    56.0   13619   22     198  1.3408773
14       2922    64.7   14575   22     192 -0.1125558
15       3950    73.0   14556   21     191  0.4668919
16       4488    78.9   18573   21     200  0.6309489
17       3295    79.4   15618   22     200  1.0918370




More information about the R-help mailing list