[R] how to selection model by BIC

Gavin Simpson gavin.simpson at ucl.ac.uk
Tue Aug 17 19:15:10 CEST 2010


On Tue, 2010-08-17 at 17:12 +0100, Xin__ Li wrote:
> Hi All:
> the package "MuMIn" can be used to select the model based on AIC or AICc.
> The code is as follows:
> 
> data(Cement)
> lm1 <- lm(y ~ ., data = Cement)
> 
> dd <- dredge(lm1,rank="AIC")
> print(dd)
> 
> If I want to select the model by BIC, what code do I need to use?

?dredge explains this a bit. The key is to write your own function to
compute BIC and use that instead. I haven't looked into this in any
detail, but the following seems to work:

BIC <- function(object, k, ...) return(AIC(object, k = k, ...))

data(Cement)
lm1 <- lm(y ~ ., data = Cement)
dd <- dredge(lm1, rank = "BIC", k = log(NROW(Cement)))
dd

The BIC function in this case works because dredge passes on the '...'
to the rank function. Which actually means, all you need to do is:

dd2 <- dredge(lm1, rank = "AIC", k = log(NROW(Cement)))
dd2

So in this case, no need for the BIC function, but I left it in in case
you ever want to have your own ranking function.

>  And when
> to select the best model based on AIC, what the differences between the
> function "dredge" in package"MuMIn" and the function "stepAIC" in package
> "MASS"

I'm not going there. This really depends on why you are doing these data
dredging steps in first place; prediction or inference. And that is
beyond the bounds of this list (for me at least).

As for differences, dredge() fits all combination of models given a set
of predictors, stepAIC() performs stepwise (forwards, backwards or both)
selection within an upper and lower scope for the models.

HTH

G

> 
> Many thanks
> 
> best wishes
> 
> XIN LI
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



More information about the R-help mailing list