ron-r
3/27/2014 - 2:27 PM

From http://stackoverflow.com/questions/9988885/backward-elimination-in-logistic-regression-using-r

myForm <- as.formula(surv~
  as.factor(tdate)+as.factor(tdate)+as.factor(sline)+as.factor(pgf)
  +as.factor(weight5)+as.factor(backfat5)+as.factor(srect2)
  +as.factor(bcs)+as.factor(loco3)+as.factor(fear3)
  +as.factor(teats)+as.factor(preudder)+as.factor(postudder)
  +as.factor(colos)+as.factor(tb5) +as.factor(respon3)
  +as.factor(feed5)+as.factor(bwt5)+as.factor(sex)
  +as.factor(fos2)+as.factor(gest3)+as.factor(int3))

sofNoMis <- sof[which(complete.cases(sof[,all.vars(myForm)])),]

FulMod2 <- glm(myForm,family=binomial(link="logit"),data=sofNoMis)

step(FulMod2,direction="backward",trace=FALSE)
OR
step(FulMod2,direction="backward",trace=FALSE,action=na.omit)
##backward / forward / both