double plogis(double x, double location, double scale, int lower_tail, int log_p) { #ifdef IEEE_754 if (ISNAN(x) || ISNAN(location) || ISNAN(scale)) return x + location + scale; #endif if (scale <= 0.0) ML_ERR_return_NAN; x = (x - location) / scale; if (ISNAN(x)) ML_ERR_return_NAN; R_P_bounds_Inf_01(x); x = exp(lower_tail ? -x : x); return (log_p ? -log1p(x) : 1 / (1 + x)); }
double plogis(double x, double location, double scale, int lower_tail, int log_p) { #ifdef IEEE_754 if (ISNAN(x) || ISNAN(location) || ISNAN(scale)) return x + location + scale; #endif if (scale <= 0.0) ML_ERR_return_NAN; x = (x - location) / scale; if (ISNAN(x)) ML_ERR_return_NAN; R_P_bounds_Inf_01(x); if(log_p) { // log(1 / (1 + exp( +- x ))) = -log(1 + exp( +- x)) return -Rf_log1pexp(lower_tail ? -x : x); } else { return 1 / (1 + exp(lower_tail ? -x : x)); } }