[R] step and glm : keep all models

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Jan 24 20:44:58 CET 2008

On Thu, 24 Jan 2008, Sylvain Bertrand wrote:

> Hi everyone,
> I'm running the following command:
>> step(mydata.glm,directions="both",trace=T)
> which returns the model with the lowest AIC.
> Now I'd like to get the list of all the models (or at least the formulas)
> that were used in between.
> I've noticed the "keep" option, but couldnt find any help on how to use it.
> Would anyone here be able to help me with this?

Did you try the example on the help page?  The final display shows you how 
to see the list of models.  Or

step(lm1, keep=function(model, aic) formula(model))$keep[1,]

(It's a bit peculiar: a formula is of length 3 but prints like length 1.)

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

More information about the R-help mailing list