I have the following issue in R.
I perform logistic regression in R:
logitMod <- glm(dependent_var ~ var1, var2, varN, data=traindata, family=binomial())
Then, I run predict on the first record of the testdata set, to get the log odds:
>predict(logitMod, testdata[1])
-44.81362
Then I calculate the probability from the log odds:
> 1/(1+ exp(-predict(logitMod, testdata[1])))
3.449006e-20
Then, I check with the predict function what the built-in probability-conversion would yield, and the result is very different:
>predict(logitMod, testdata[1], type="response")
2.220446e-16
So my question is, what am I overlooking?
predict(logitMod, testdata[1], type="response")
produces erroneous predictions. But maybe there are good reasons for this behaviour ofpredict.glm
. $\endgroup$predict.glm
was implemented to have this behaviour. Btw,2.22e-16
is the same as.Machine$double.eps
. $\endgroup$