[R] glm syntax question

maud
Tue, 15 Apr 2008 09:07:18 -0000

Hello,

I'm new to R and have a very basic syntax question for the
functionglm. I am using the function glm() to do a regression on a
data set. I want to run this function in a while loop, so I need to be
able to do two things:

(1) I need to be able to have my list of variables in the regression
be based from a variable vector instead of hard code.
(2) I need to be able to collect the significant variables from the
output of the regression in a vector.

As example code consider:

out <- glm(Var_0~Var_1+Var_2, family=binomial(link=logit),
data=MyData)

and if I then execute summary(out) I get a summary of the output
including a table

Coefficients:
            Estimate Std. Error z value Pr(>|z|)
(Intercept) -2.92995    0.08731 -33.558  < 2e-16 ***
Var_1     1.39244    0.10979  12.683  < 2e-16 ***
Var_2  0.86091    0.09650   8.922  < 2e-16 ***

For (1) I would like some code analogous to the following (which
doesn't work)

VarVec <- c("Var_1","Var_2")
out <- glm(Var_0~VarVec, family=binomial(link=logit), data=MyData)

For (2) I would like to be able to access the table shown above (which
is only part of what summary(out) displays). I'd like something like

table <- summary(out)
SigVars <- table[Pr(>|z|) < .001]

that is collect all of the variables with a Pr(>|z|) value less than .
001.

Thanks!