Bug 22502 – Potential error where std.internal.math.gammafunction.betaIncompleteInv gives different results from Wolfram Alpha for parameters aa and bb being half integer and yy0 being 0.025.
Status
RESOLVED
Resolution
INVALID
Severity
minor
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2021-11-10T16:42:48Z
Last change time
2021-11-10T17:30:51Z
Assigned to
No Owner
Creator
alex
Comments
Comment #0 by alex — 2021-11-10T16:42:48Z
So I was trying to match a table in this article (https://www.jstor.org/stable/2676784), in particular Table 5. which basically corresponds to betaIncompleteInverse(x+1/2,N-x+1/2,0.05/2). Using Wolfram Alpha I can match the table, but I am getting numbers which seem surprisingly off when using betaIncompleteInverse.
For example:
InverseBetaRegularized[0.05/2, 7+1/2, 1+1/2] == 0.546280678967585... and betaIncompleteInv(7+1/2,1+1/2,0.05/2) ~= 0.590384
So I did a few sanity checks using the test cases in the unittests in the file (https://github.com/dlang/phobos/blob/v2.098.0/std/internal/math/gammafunction.d). For example:
InverseBetaRegularized[0.0109343152340992, 8, 10] == 0.2 just like betaIncompleteInv(8, 10, 0.010_934_315_234_099_2L) ~= 0.2
Based on that I think I am using the function correctly, it is still possible I am doing something wrong though.
Using the program:
```
import std.mathspecial;
import std.stdio;
real jefferys(real x, real N, real alpha=0.05){
return betaIncompleteInverse(x+1/2,N-x+1/2,alpha/2);
}
int main(){
for(real N =7; N< 10; N++){
for(real x=1; x < N;x++){
writef("(%f,%f) %f\n", N,x,jefferys(x,N));
}
}
return 0;
}
```
and Wolfram Alpha like (https://www.wolframalpha.com/input/?i=InverseBetaRegularized%5B0.05%2F2%2C+1%2B1%2F2%2C+7-1%2B1%2F2%5D), just varying the parameters and Table 5 from the article I linked I get:
(N,x) Wolfram D Table 5
(7,1) 0.0158765... 0.004211.. 0.016
(7,2) 0.0647282... 0.043272.. 0.065
(7,3) 0.1388642... 0.118117.. 0.139
(7,4) 0.2345012... 0.222778.. 0.234
And so on.
Sorry if this is just some kind of user error on my part.
Comment #1 by kinke — 2021-11-10T17:28:41Z
`+1/2` adds a `0` integer. With `+0.5`, the results should match.
Comment #2 by alex — 2021-11-10T17:29:52Z
(In reply to kinke from comment #1)
> `+1/2` adds a `0` integer. With `+0.5`, the results should match.
Awesome, thank you! I figured I was doing something stupid.