In logistic regression, the probability is obtained from
$$
Pr = \frac{\exp(X\beta)}{1 + \exp(X\beta)} ~~~~ (1)
$$
From the plot below, it is obvious that if $X\beta$ > 10, the probability approaches 1
In my case (a penalized logistic regression, details are omitted), my estimate for $\beta$ (and therefore $X\beta$) is very large, > 2000, when plugging the equation (1), R gives out Inf
.
(Updated details based on @whuber comments: I actually also have some negative values, say, <-2000, so the alternative Equation (2) is not working) $$ Pr = \frac{1}{1+\exp(-X\beta)} ~~~~~~~(2) $$
I am looking for some suggestions on how to deal with this situation, where the output is $Pr$.
Possible two approaches I can think of are:
- Use the
if
-condition: If $X\beta$ > 10, then Pr = 1; to compute the probability and skip the equation (1). - Check my code on the estimation of $\beta$. (though I do not think my code has bugs)
- (based on @whuber's comments) If $X\beta$ is positive, use Equation (2); if $X\beta$ is negative, use Equation (1).
- (based on @BenBolker's comments) Use the R function plogis() to compute the $Pr$, which is the logistic of $X\beta$. The code is
plogis(c(-2000,2000), lower.tail=TRUE)
. A related article is here.