[R] how to keep the dropped term at each step when calling "step"?

From: Riyan Cheng <rcheng_at_purdue.edu>
Date: Wed 07 Dec 2005 - 05:21:21 EST


Hi all:

I am using the R function "step" to perform a model selection in backward direction. I'd like to automatically keep the dropped term at each step. So I wrote a filter function for the "keep" argument. However, the filter function cannot change the value of external variable and so doesn't work well. Anybody can help? Thank you in advance!

Regards,
Riyan Cheng

P.S., R code

###########################################
example(lm)
lm1 <- lm(Fertility ~ ., data = swiss)

tm<- attr(lm1$terms,"term.labels")

kp<- function(obj,aic){
  x<- attr(obj$terms,"term.labels")
  y<- setdiff(tm,x)
  if(length(y)==0)y=NULL
  tm<- x
  AIC<- aic

  list(n=length(x),dropped=y,AIC=aic)
}

g<- step(lm1,keep=kp,k=10)
g$keep

##############################################


______________________________________________

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 Wed Dec 07 06:24:59 2005

This archive was generated by hypermail 2.1.8 : Wed 07 Dec 2005 - 09:36:57 EST