Skip to content

stepwise regression-fitting all possible models

2 messages · aspa, Steve Lianoglou

#
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.

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
#
Hi,
On Tue, Apr 13, 2010 at 12:51 PM, aspa <a.angelakopoulou at gmail.com> wrote:
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