normal cdf function gives probability of 0.0 for very low probabilities
robinpaul85 opened this issue · comments
I have noticed that for very low probability the normal cdf function gives a probability of 0.0 when actual probability are in the order of 10^(-30)
I can't reproduce this. If I evaluate the CDF of a normal distribution with mean 0 and standard deviation 1 at x = -35.0, I get 1.124910706417e-268.
Can you provide code that gives a minimal working example that shows the unexpected result?
The expression 1 - cdf(x)
is often called the complementary CDF or the survival function. For values of x
that are sufficiently large, actually computing it with the expression 1 - cdf(x)
is not a good method, as you have observed. The problem is that with x
that large, cdf(x)
is numerically 1.0. So you end up with 1 - cdf(x) = 1 - 1 = 0
.
Fortunately the sf
method was added to the continuous distributions in version 0.16 of statrs
, so if you are using the latest version, you can compute the desired quantity with the new method. Using the names from your code sample, that would be p_g = n.sf(z);
.
If you can't upgrade statrs
, a simple fix is to use the symmetry of the normal distribution: sf(μ + x) = cdf(μ - x)
.