[R] Issue with step(): Fails to look for object$model

Adam D. I. Kramer adik at ilovebacon.org
Sun Feb 15 03:44:13 CET 2009


 	I'm playing around with stepwise regression, using the step
function, and believe I have found a bug (or at least, a strong case for

> ex <- data.frame(y=rnorm(100),x=rnorm(100))
> l <- lm(y ~ x, data=ex)
> step(l) 
[output is correct]
> rm(ex)
> step(l)
Start:  AIC=11.79
y ~ x

        Df Sum of Sq     RSS     AIC
- x     1     0.120 108.221   9.900
<none>              108.100  11.789
Error in inherits(x, "data.frame") : object "ex" not found

...ex is not found, so step fails. However, all of the necessary data to run
the step function is present in l$model.

I would also argue that step() *should* use l$model if at all possible, as
it seems reasonable to expect that ex may undergo changes. Further, step()
does not appear to test any other columns present in ex (even if
direction="both" is specified), unless they are specified in scope.

If I am misunderstanding step() or if there is a good reason why it operates
this way, please let me know!


More information about the R-help mailing list