1

I created a stepwise regression using the codes below:

set.seed(1)
y=rnorm(100,20)
a=sqrt(rnorm(100,40))-15
b=rnorm(100,50)/abs(a)
c=sqrt(b+y)
d=rnorm(100,13)+sqrt(abs(a))

test_data <- data.frame(y,a,b,c,d)

step1<- step(lm(y~a+b+c+d,data=test_data),direction="backward")
summary(step1)

The stepwise regression gave me this formula lm(formula = y ~ b + c, data = test_data). Meaning I can get the best model if I used b and c to predict y.

What I want to know is if there is an automatic code/way to create a data frame containing the significant independent variables and dependent variable like: data.frame(test_data$y,test_data$b,test_data$c).

Thanks in advance.

jbest
  • 640
  • 1
  • 10
  • 28
  • 1
    [This answer](http://stackoverflow.com/a/5587781/4002530) and the linked blog post may be of help. – tospig May 05 '15 at 06:54
  • Thanks for the link. I found a simple solution. I only used this formula `newdf<- (step1$model)` – jbest May 05 '15 at 07:09

0 Answers0