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

Reply via email to