[R] Problem with the step() function

Luis Torgo ltorgo at liacc.up.pt
Mon Mar 24 18:01:11 CET 2003


Dear all,
I'm having some problems with using the step() function inside another 
function. I think it is an environment problem but I do not know how to 
overcome it. Any suggestions are appreciated. 

I've prepared a simple example to illustrate my problem:

> library(MASS)
> data(Boston)
> my.fun <- function(dataset) {
+   l <- lm(medv ~ .,data=dataset)
+   final.l <- step(l)
+ }
> model <- my.fun(Boston)
Start:  AIC= 1589.64 
 medv ~ crim + zn + indus + chas + nox + rm + age + dis + rad +  
    tax + ptratio + black + lstat 

          Df Sum of Sq     RSS     AIC
- age      1       0.1 11078.8  1587.6
- indus    1       2.5 11081.3  1587.8
<none>                 11078.8  1589.6
- chas     1     219.0 11297.8  1597.5
- tax      1     242.3 11321.0  1598.6
- crim     1     243.2 11322.0  1598.6
- zn       1     257.5 11336.3  1599.3
- black    1     270.6 11349.4  1599.9
- rad      1     479.2 11557.9  1609.1
- nox      1     487.2 11565.9  1609.4
- ptratio  1    1194.2 12273.0  1639.4
- dis      1    1232.4 12311.2  1641.0
- rm       1    1871.3 12950.1  1666.6
- lstat    1    2410.8 13489.6  1687.3
Error in model.frame.default(formula = medv ~ crim + zn + indus + chas +  : 
	Object "dataset" not found

Apparently the step() function is not able to find the "dataset" object which 
is created inside the my.fun() function.

My system information:
> R.version
         _                
platform i686-pc-linux-gnu
arch     i686             
os       linux-gnu        
system   i686, linux-gnu  
status                    
major    1                
minor    6.1              
year     2002             
month    11               
day      01               
language R

Thank you for any hints.

-- 
Luis Torgo
    FEP/LIACC, University of Porto   Phone : (+351) 22 607 88 30
    Machine Learning Group           Fax   : (+351) 22 600 36 54
    R. Campo Alegre, 823             email : ltorgo at liacc.up.pt
    4150 PORTO   -  PORTUGAL         WWW   : http://www.liacc.up.pt/~ltorgo



More information about the R-help mailing list