Using scope in Stepwise (both)

Hi! I'm trying to complete stepwise regression using forward, backward, and both. My data includes multiple dummy variables. This isn't a problem for my forward and backward however, when I run "both" it references my original dataset rather than the dummy variables I've created. To avoid this, I've tried using scope however, somewhere I am going wrong. Below is my code as well as the error I receive:

step(lm(lifesat~., data=na.omit(final4)),direction="both", scope=(lifesat~age+male+notmarried+income+physical+child+ses+nosmoke+spirit+college+advanced+job+psych))

step(lm(lifesat~., data=na.omit(final4)),direction="both", scope=(lifesat~age+male+notmarried+income+physical+child+ses+nosmoke+spirit+college+advanced+job+psych))
Start: AIC=181.63
lifesat ~ subject + age + gender + married + psych + ses + child +
physical + smoke + spirit + edu + job + income + male + notmarried +
nosmoke + college + advanced

Error in factor.scope(ffac, list(add = fadd, drop = fdrop)) :
upper scope has terms ‘subject’, ‘gender’, ‘married’, ‘smoke’, ‘edu’ not included in model

Thank you in advance for your help!

I don't see anything about dummy variables in what you provided... so I wont comment on that.

When you use scope, it should potentially include more variables than was in the original fit object, but not less, I think that explains the error shown here.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.