[R] Odd behaviour of step (and stepAIC)?

Berwin A Turlach berwin at maths.uwa.edu.au
Sat Mar 20 09:18:57 CET 2004


>>>>> "JO" == Jari Oksanen <jari.oksanen at oulu.fi> writes:

    JO> There seems to be some obscure features in step() when you
    JO> have interaction terms: their interpretation is order
    JO> sensitive. [...]  Just because R internally decides to order
    JO> terms differently than in the scope (this may happen even when
    JO> you have produced the scope by first fitting the maximal
    JO> model, and then extracting that using scope=formula()). I once
    JO> was diligent enough to trace this to a certain C function
    JO> where this ordering was done, but I was not clever enough to
    JO> instantly know how to change the behaviour.
It is well possible that this may be occasionally a problem.  (I
remember that a colleague of mine once showed me a problem were the
behaviour of step depended on how you specified the code.  However, I
believe more recent version of R don't show that behaviour anymore.)

But I don't believe that this is the problem in Bob's case:
    >> I'm getting the following from a stepwise selection (with both step 
    >> and stepAIC):
    >> 
    >> > step(lm(sqrt(Grids)~ SE + Edge + NH), scope=~ (Edge + SE + NH)^2)
    >> Start:  AIC= 593.56
    >> sqrt(Grids) ~ SE + Edge + NH
    >> 
    >> Df Sum of Sq              RSS    AIC
    >> <none>                 2147.0  593.6
    >> + Edge:NH  1       3.0 2143.9  595.1
    >> + SE:NH    4      23.2 2123.8  598.4
    >> - NH       1      75.8 2222.8  601.6
    >> - Edge     1     448.7 2595.7  646.4
    >> - SE       4    1033.7 3180.6  699.1
    >> 
    >> 
    >> My problem is that the SE:Edge term is not added.
If you look at the output, adding the SE:Edge term decreases RSS but
increases AIC.  The increase in parameters is not worth the decrease
in RSS, according to the AIC criterion.  step tries to find the best
AIC model, i.e., the current model is the best.

Cheers,

        Berwin

========================== Full address ============================
Berwin A Turlach                      Tel.: +61 (8) 6488 3338 (secr)   
School of Mathematics and Statistics        +61 (8) 6488 3383 (self)      
The University of Western Australia   FAX : +61 (8) 6488 1028
35 Stirling Highway                   
Crawley WA 6009                e-mail: berwin at maths.uwa.edu.au
Australia                        http://www.maths.uwa.edu.au/~berwin




More information about the R-help mailing list