Tue 02 Dec 2014 03:53:58 PM UTC, comment #6:
Hello,
Well, for x >= n, binocdf(x, n, p) is exactly 1 and hence binocdf(x, n, p, "upper") is exactly 0. For x < n but x being "close" to n, binocdf(x, n, p) tends to be close to 1, especially if p is close to 0.
Conversely, for x < 0 we have exactly binocdf(x, n, p) == 0 and binocdf(x, n, p, "upper") == 1. For x >= 0 but close to 0 and p close to 1, binocdf(x, n, p) is close to 0 and binocdf(x, n, p, "upper") is close to 1 (possibly equal to 1 within machine precision).
I think it is best to always use betainc(p, x + 1, n - x) for the "upper" case and betainc(1 - p, n - x, x + 1) otherwise.
The user should call binocdf(x, n, p) if he is interested in the probability of a binomially distributed random variable being <= x and binocdf(x, n, p, "upper") for the probability of it being > x.
Falk
|
Sun 30 Nov 2014 08:08:42 PM UTC, comment #5:
Hi,
better than my quick & dirty patch :-)
We should add
and some explanation about the "upper" paameter. I will try
to write something.
Is there a way to know in advance which of
Has a better accuracy? We can use it also for the non-lower case.
Avinoam
|
Sun 30 Nov 2014 01:18:17 PM UTC, comment #4:
Well, that's a quick&dirty fix for someone needing just approximate Matlab compatibility; however it doesn't solve the problem of accuracy - results below 1e-16 will be wrongly returned as 0, which for many practical purposes is not acceptable.
I attach another version of binocdf.m where in case of "upper",
is called instead of
which avoids this loss of accuracy.
For instance,
yields
while with my version
yields
I also added a test case
Of course, binocdf() is just one among many other CDF and analogous fixes have to be applied for all the other xxxcdf functions listed on https://www.gnu.org/software/octave/doc/interpreter/Distributions.html#Distributions - that's a considerable amount of work!
(file #32575)
|
Sat 29 Nov 2014 11:00:08 PM UTC, comment #3:
Hi,
Please check the attached modified binocdf.m
If the 4th argument is "upper", the result is
1-cdf (X,N, p).
There is no documentation yet.
There is no treatment in special points.
Thanks,
Avinoam
(file #32571)
|