[R] How to get the variables used in stepwise logistic regression?

David Winsemius dwinsemius at comcast.net
Fri Feb 4 18:07:03 CET 2011


On Feb 4, 2011, at 11:56 AM, Soyeon Kim wrote:

> Dear All,
>
> I used glm and then used step function for stepwise regression.
> Now, I want to store the variables used in the stepwise regression.

I am not sure that what you ask here is actually what you eventually  
ask and will limit my answer to only what you ask below.

>
> The code is the following.
>
> m_logistic <- glm(y ~ . + M1:T + M2:T + M3:T+ M4:T +M5:T,
> family=binomial("logit"), data = data)
>  step_glm <- step(m_logistic)
>
>> step_glm$terms
> y ~ M1 + T + M1:T
> attr(,"variables")
> list(y, M1, T)
> attr(,"factors")
>   M1 T M1:T
> y   0 0    0
> M1  1 0    1
> T   0 1    1
> attr(,"term.labels")
> [1] "M1"   "T"    "M1:T"
> attr(,"order")
> [1] 1 1 2
> attr(,"intercept")
> [1] 1
> attr(,"response")
> [1] 1
> attr(,".Environment")
> <environment: R_GlobalEnv>
> attr(,"predvars")
> list(y, M1, T)
> attr(,"dataClasses")
>        y        M1         T
> "numeric" "numeric" "numeric"
>
> How can I extract only "term.labels" ?
>

Have you tried what would seem to be the obvious answer (assuming that  
is a faithful console output):

attr(step_glm$terms,  "term.labels")

?attr
?attributes

(And the usual caveats: stepwise methods are often invalid.)

-- 
David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list