[R] Step error

vasilis pappas vasileios_p at yahoo.gr
Wed Mar 30 20:24:13 CEST 2005


Could anyone tell me what am I doing wrong?

> pro<-function(indep,dep){
+  d<-data.frame(indep)
+  form<-formula(lm(dep~.,data=d))
+ 
forward<-step(lm(dep~X1,data=d),scope=form,trace=0,direction='f')
+  return(forward) 
+ }
> pro(m,q)
Error in inherits(x, "data.frame") : Object "d" not
found

Where q is a vector with the dependent variable's
values
and m is a matrix containing the values of the
independent variables.

While writing the above without a function form has no
problem, that is :

> d<-data.frame(m)
> form<-formula(lm(q~.,data=d))
>
forward<-step(lm(q~X1,data=d),scope=form,trace=0,direction='f')
> forward

Call:
lm(formula = q ~ X1 + X2 + X5, data = d)

Coefficients:
(Intercept)           X1           X2           X5  
    -15.798        8.765        6.774       -4.245  


Thank you in advance!
Vasilis




More information about the R-help mailing list