I have a set of possible predictors for a binary outcome. In order to obtain the best model, I start from the zero model, and do a stepwise selection (in R) in order to obtain the best predictors. The way R (or any other program) does this is by minimizing the AIC. How come the final chosen subset can still contain insignificant predictors?
In order to obtain the best model, I start from the zero model, and do a stepwise selection (in R) in order to obtain the best predictors.
As has been discussed here and elsewhere, this does not produce the "best" model for any sensible definition of "best". It produces a model where the parameter estimates are biased away from 0, the standard errors are biased toward 0, the final model is too complex and (most importantly) the data analyst (you) have been prohibited from thinking.
As to which variables are left in the final model and their (incorrectly estimated) p values in the final model, there's no mystery. You are selecting on AIC rather than p value. If you are using the stepAIC model, then it doesn't even let you select p values to use for entering and leaving the model.