Skip to content
Back to formatted view

Raw Message

Message-ID: <002501c5fa91$defa1360$0602a8c0@rwd>
Date: 2005-12-06T18:21:21Z
From: Riyan Cheng
Subject: how to keep the dropped term at each step when calling "step"?

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
##############################################