The code in the stan/math/prim/scal/fun/inv_logit.hpp is just:
inline double inv_logit(double a) {
using std::exp;
return 1.0 / (1.0 + exp(-a));
}
That should not produce an infinite result. If exp(-a) rounds
to zero, it returns 1, whereas if it goes to infinity, it should return
zero.
I'd like to see the value of the argument (beta0 + beta1 * predictor[n])
and the result p_pred[n] here if those tests succeed. So could you try
changing the generated quantities test to print like this:
p_pred[n] = inv_logit(beta0 + beta1 * predictor[n]);
if (p_pred[n] == positive_infinity()) {
print("+inf: ", "beta0 + beta1 * predictor[", n, "]=", beta0 + beta1 * predictor[n],
" p_pred = ", p_pred[n]);
p_pred[n] = 1;
}
if (p_pred[n] == negative_infinity()) {
print("-inf: ", "beta0 + beta1 * predictor[", n, "]=", beta0 + beta1 * predictor[n],
" p_pred = ", p_pred[n]);
p_pred[n] = 0;
}
and see if those tests ever get called.
- Bob