[R] stepAIC invalid scope argument

Adaikalavan Ramasamy ramasamy at cancer.org.uk
Tue Aug 16 06:09:35 CEST 2005


Thank you. Your suggestion is equivalent is the same as my second
stepAIC command that failed in R-2.1.1.

See Prof. Ripley's reply where he pointed out that this was due to using
the name 'df' which clashes with built-in function with the same name
from stats package.

Regards, Adai


On Tue, 2005-08-16 at 15:52 +0100, John Wilkinson (pipex) wrote:
> Adai,
> 
> The following works.Perhaps you should define your 'upper' and 'lower'
> in the list as aov's, as you have done with your lo,hi and mid.
> 
> John
> 
> >  stepAIC( mid, scope=list(upper = mid , lower = lo) )
> Start:  AIC= -594.66 
>  y ~ x2 + x3 
> 
>        Df Sum of Sq     RSS     AIC
> - x2    1      0.11  548.56 -596.45
> - x3    1      0.95  549.40 -594.93
> <none>               548.45 -594.66
> 
> Step:  AIC= -596.45 
>  y ~ x3 
> 
> Adaikalavan Ramasamy wrote ---
> 
> 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 argumen
> 
>




More information about the R-help mailing list