I am running a logistic regression in R and doing “backward elimination” inorder to get my final model:
FulMod2 <- glm(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),
family=binomial(link="logit"),data=sof)
When trying to run the backward elimination script:
step(FulMod2,direction="backward",trace=FALSE)
I got this error message:
Error in step(FulMod2, direction = "backward", trace = FALSE) :
number of rows in use has changed: remove missing values?
This is the second model that I am running using the backward elimination function. The first model was fine when I did backward elimination to get my final model.
Any help would be very much appreciated!
Baz
In order to successfully run
step()on your model for backwards selection, you should remove the cases insofwith missing data in the variables you are testing.In your comment, you mentioned that 1 out of 9 cases has missing data. However, I recommend checking that again with the above code, in case some of that missingness corresponded to variables not included in
FulMod2. If you still have many incomplete cases, you might want to decide a priori if you can eliminate some of the variables with high missingness.