[R] find lowest AIC of a LM

Ben Bolker bbolker at gmail.com
Thu Apr 18 19:00:27 CEST 2013

Fabio Berzaghi <fabe <at> dmu.dk> writes:

> hello all,
> I have a simple linear model with 4/5 variables that I am trying to fit. 
> I would like to find the lowest AIC value with any combination of all 
> the variables. I would like to implement this with a while/for loop. 
> Possibly I would like to generalize this so then I can use it when I 
> have many more variables. I do not want to use step AIC. At the moment I 
> am doing it manually but I would like to automate the process because I 
> have many species. I want to compute all possible combinations with all 
> the variables and know which combination gives the lowest AIC.
> My function looks like this 


  You should really use a data argument, i.e.


(It won't change the answers but it will make everything work
better if you want to post-process the fit, e.g updating or

> I cannot seem to find a library that has a function that does this 
> automatically.

  Check out the MuMIn, AICcmodavg, and glmulti packages.

More information about the R-help mailing list