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.