Hello,
I met this problem with the function step( ) when I was trying to do forward
variable selection. Below is the code I used and the error message. I don't
why I am getting this error message. Could someone help me out. I noticed
that I got this error message whenever it chose a model with an interaction
term X_p :X_q and if I put X_q before X_p in the upper scope formula, like
X_q*X_p***. Shouldn't X_p:X_q be the same as X_q:X_p? So why am I getting
this error message? Any help is greatly appreciated.
> x1<-rnorm(100,0,1)
> x2<-rnorm(100,0,1)
> x3<-rnorm(100,0,1)
> y<-x1+x2+2*x3+2*x1*x3+rnorm(100,0,1)
> datasim<-data.frame(cbind(y,x1,x2,x3))
>
steplm<-step(lm(y~1,data=datasim),scope=list(upper=~x1*x2*x3,lower=~1),direction="forward",trace=1)
Start: AIC= 274.81
y ~ 1
Df Sum of Sq RSS AIC
+ x3 1 615.97 914.34 225.30
+ x1 1 139.97 1390.34 267.21
+ x2 1 83.42 1446.90 271.20
<none> 1530.32 274.81
Step: AIC= 225.3
y ~ x3
Df Sum of Sq RSS AIC
+ x1 1 184.94 729.40 204.71
+ x2 1 53.87 860.48 221.23
<none> 914.34 225.30
Step: AIC= 204.71
y ~ x3 + x1
Df Sum of Sq RSS AIC
+ x1:x3 1 533.91 195.49 75.03
+ x2 1 47.44 681.96 199.98
<none> 729.40 204.71
Step: AIC= 75.03
y ~ x3 + x1 + x3:x1
Error in factor.scope(ffac, list(add = fadd, drop = fdrop)) :
upper scope does not include model
Thanks,
Min
[[alternative HTML version deleted]]