Dear all,
am I doing something wrong, or is this a bug (R 2.0.1 & 1.9.1,
linux&windows):
> library(MASS)
> df <- data.frame(x = rnorm(100), y = rnorm(100), z = rnorm(100))
> f <- lm(x ~ y + z, data = df)
> stepAIC(f, scope = list(upper = ~y * z, lower = ~1))
Start: AIC= -16.56
x ~ y + z
Error in eval(expr, envir, enclos) : invalid second argument
>
I can avoid the problem doing the following, but in my application I do
not want to use attach / detach because of possible name conflicts:
> attach(df)
> f <- lm(x ~ y + z)
> stepAIC(f, scope = list(upper = ~y * z, lower = ~1))
Start: AIC= 23.55
x ~ y + z
...
Call:
lm(formula = x ~ 1)
Coefficients:
(Intercept)
-0.1972
> detach(df)
Thanks for any help,
Klaus Thul
Prof Brian Ripley
2004-Dec-26 15:56 UTC
[R] Problem with stepAIC, "invalid second argument"
Try ?df to see what you did wrong! Always use conflicts() before posting to see what you have overridden. R normally allows you to get away with masking objects, but in this case it is the R object that is masking yours. On Sun, 26 Dec 2004, Klaus Thul wrote:> am I doing something wrong, or is this a bug (R 2.0.1 & 1.9.1, > linux&windows): > > > library(MASS) > > df <- data.frame(x = rnorm(100), y = rnorm(100), z = rnorm(100)) > > f <- lm(x ~ y + z, data = df) > > stepAIC(f, scope = list(upper = ~y * z, lower = ~1)) > Start: AIC= -16.56 > x ~ y + z > Error in eval(expr, envir, enclos) : invalid second argument-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595