Try
On Tue, Apr 15, 2008 at 6:07 AM, maud <maud.july@gmail.com> wrote:
> 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)
form <- as.formula(paste("Var_0", paste(VarVec,
collapse="+"), sep = " ~ "))
out <- glm(form, 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
>
SigVars <- summary(out)$coefficients[,4]
SigVars[SigVars < .001]
>
> table <- summary(out)
> SigVars <- table[Pr(>|z|) < .001]
>
> that is collect all of the variables with a Pr(>|z|) value less than .
> 001.
>
> Thanks!
>
> ______________________________________________
> R-help@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.
>
--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O
[[alternative HTML version deleted]]