0

I run this program:

#include <gsl/gsl_math.h>
#include <stdio.h>

int main(){
    double x= 0.5;
    double res = gsl_cdf_ugaussian_Pinv(x);
    printf("icdf(%f)=%f\n",x,res);
    return 0;
}

For some reason the output is: icdf(0.500000)=1.000000

Which is wrong, it should be: icdf(0.500000)=0.000000

Did I do something wrong?

tod
  • 1,539
  • 4
  • 17
  • 43
dafnahaktana
  • 837
  • 7
  • 21

2 Answers2

0

The inverse cumulative distributions, x=P^{-1}(P) and x=Q^{-1}(Q) give the values of x which correspond to a specific value of P or Q. They can be used to find confidence limits from probability values.

I think, that this is a correct output.

ivg
  • 34,431
  • 2
  • 35
  • 63
0

The header file gsl/gsl_math.h doesn't include the prototypes for the probability distribution functions. This means the compiler hasn't seen a declaration of gsl_cdf_ugaussian_Pinv(x), so it thinks the function returns an integer. When I compile your code, I get a warning about this, and when I run it, I get:

icdf(0.500000)=256835073.000000

which is obviously wrong. When I change this

#include <gsl/gsl_math.h>

to

#include <gsl/gsl_cdf.h>

the file compiles with no warning, and gives:

icdf(0.500000)=0.000000

as expected.

See http://www.gnu.org/software/gsl/manual/html_node/Random-Number-Distribution-Examples.html#Random-Number-Distribution-Examples for another example (scroll down to the bottom).

Warren Weckesser
  • 110,654
  • 19
  • 194
  • 214