Hi,

        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
improvement):

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!

--Adam

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to