how to selection model by BIC

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

how to selection model by BIC

Xin__ Li
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? 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"

Many thanks

best wishes

XIN LI

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: how to selection model by BIC

bbolker
Xin__ Li <msf09xl <at> mail.wbs.ac.uk> writes:

>
> 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?

  I was going to be grumpy at you for not using common sense, but it's
not quite as obvious as I thought.

library(stats4)
dd <- dredge(lm1, rank="BIC")

  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"
>

  stepAIC uses a stepwise procedure, dredge evaluates all (sensible)
model subsets.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: how to selection model by BIC

Gavin Simpson
In reply to this post by Xin__ Li
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]]
>
> ______________________________________________
> [hidden email] 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
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

______________________________________________
[hidden email] 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.