[R] stepAIC invalid scope argument

From: Adaikalavan Ramasamy <ramasamy_at_cancer.org.uk>
Date: Mon 15 Aug 2005 - 10:37:37 EST


I am trying to replicate the first example from stepAIC from the MASS package with my own dataset but am running into error. If someone can point where I have gone wrong, I would appreciate it very much.

Here is an example :

 set.seed(1)
 df <- data.frame( x1=rnorm(1000), x2=rnorm(1000), x3=rnorm(1000) )  df$y <- 0.5*df$x1 + rnorm(1000, mean=8, sd=0.5)  # pairs(df); head(df)

 lo  <- aov( y ~ 1, data=df )
 hi  <- aov( y ~ .^2, data=df )
 mid <- aov( y ~ x2 + x3, data=df )

Running any of the following commands

 stepAIC( mid, scope=list(upper = ~x1 + x2 + x3 , lower = ~1) )
 stepAIC( mid, scope=list(upper = hi , lower = lo) )
 addterm( mid, ~ x1 + x2 + x3 )
 addterm( lo, hi )

gives the same error message :
  Error in eval(expr, envir, enclos) : invalid second argument

Here is a traceback of the first failed command :

  1. eval(predvars, data, env)
  2. model.frame.default(formula = y ~ x2 + x3 + x1, data = df, drop.unused.levels = TRUE)
  3. model.frame(formula = y ~ x2 + x3 + x1, data = df, drop.unused.levels = TRUE)
  4. eval(expr, envir, enclos)
  5. eval(mf, parent.frame())
  6. lm(formula = y ~ x2 + x3 + x1, data = df, method = "model.frame")
  7. eval(expr, envir, enclos)
  8. eval(fcall, env, parent.frame())
  9. model.frame.lm(fob, xlev = object$xlevels)
  10. model.frame(fob, xlev = object$xlevels)
  11. stats:::add1.lm(object, scope = scope, scale = scale)
  12. addterm.lm(fit, scope$add, scale = scale, trace = max(0, trace - 1), k = k, ...)
  13. addterm(fit, scope$add, scale = scale, trace = max(0, trace - 1), k = k, ...)
  14. stepAIC(mid, scope = list(upper = ~x1 + x2 + x3, lower = ~1))

Any pointers would be much appreciated. Thank you.

Regards, Adai



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Mon Aug 15 22:43:18 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:39:49 EST