[R] Problem with stepAIC, "invalid second argument"
Klaus Thul
klaus_thul at yahoo.com
Sun Dec 26 16:14:42 CET 2004
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
More information about the R-help
mailing list