[R] stepwise regression-fitting all possible models

Steve Lianoglou mailinglist.honeypot at gmail.com
Tue Apr 13 20:24:28 CEST 2010


Hi,

On Tue, Apr 13, 2010 at 12:51 PM, aspa <a.angelakopoulou at gmail.com> wrote:
>
> Dear All,
>
> I am new to R and I would like to do the following:
>
> I want to fit a logistic model with 3 predictors and then perform a stepwise
> regression to select the best possible model using either the AIC/BIC
> criterion.
>
> I have used the stepAIC function which works fine but using this method only
> likely candidates are evaluated (i.e. not all the models are fitted). We
> should have 2^3=8 possible models.
>
> So I want to do the following. Write a code in R which will allow me to fit
> all 8 possible models. So, i guess the first combination will be c(0,0,0)
> for the 3 predictors, then c(0,0,1) for then next one and so one until 8
> models are fitted.

It seems like this little piece of code should get you going:

R> expand.grid(0:1, 0:1, 0:1)
  Var1 Var2 Var3
1    0    0    0
2    1    0    0
3    0    1    0
4    1    1    0
5    0    0    1
6    1    0    1
7    0    1    1
8    1    1    1

It sounds like you know what you want to do next given all these
possible permutations ...

-steve

>
> I would be really grateful if I could get some advise as to how to write the
> coding to tell R to fit each of these models in turn and extract the
> log-likelihood for each one of them so that I will be able to calculated
> AIC/BIC afterwards.
>
> Many thanks for your help,
> A
> --
> View this message in context: http://n4.nabble.com/stepwise-regression-fitting-all-possible-models-tp1838735p1838735.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>



-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact



More information about the R-help mailing list