-2

Could you please let me know how to get the full p-value from gsl_cdf_tdist_P function when p-value is smaller than 1E-16? I am getting 0 instead.

Thanks, Woody

print "t-test p-value = " . ttest(\@n,\@t) . "\n";

sub ttest{

    my ($n,$t) = @_;
    my @n = @$n;
    my @t = @$t;
    my $nn = pdl(@n);
    my $tt = pdl(@t);
    my ($tstats, $df) = t_test( $nn, $tt );
    use PDL::GSL::CDF; 
    my $p_2tail = 2 * (1 - gsl_cdf_tdist_P( $tstats->abs, $df ));
    return $p_2tail;
}

My input values as follows:

my @n = qw (1 2 4 2 3 1 2 4 2 1 2 4 2 3 1 2 4 2 1 2 4 2 3 1 2 4 2);
my @t = qw (11 12 13 12 13 11 14 11 12 13 12 13 11 14 11 12 13 12 13 11 14);
Woody Lin
  • 11
  • 2
  • Welcome to Stack Overflow! Please take the Tour http://stackoverflow.com/tour and read about the topics you actually can ask here http://stackoverflow.com/help/on-topic. You can also visit the meta site to learn how to ask questions on stack overflow http://meta.stackoverflow.com/ – Explorer Jan 05 '17 at 18:46
  • 1
    @Novice The question is perfectly on-topic, although the OP could have explained it better. He's asking why the function `gsl_cdf_tdist_P` in the Perl module [PDL::GSL::CDF](https://metacpan.org/pod/PDL::GSL::CDF#gsl_cdf_tdist_P) (yes, it's a real module) is returning zero when the expected value is smaller than 1E-16. I'm guessing the issue is that he's using `print`, which on many systems only keeps 15 digits of precision. – ThisSuitIsBlackNot Jan 05 '17 at 18:54
  • 3
    @WoodyLin Can you please [edit] your question to show the exact code you're using? – ThisSuitIsBlackNot Jan 05 '17 at 18:55
  • @ThisSuitIsBlackNot Yes, I think that the `print` function might be problmatic since `gsl_cdf_tdist_P` should return a double number. Is there a way to print all digits after decimal? – Woody Lin Jan 06 '17 at 11:00
  • In general you can use `sprintf` with `%.f` where n is the number of decimals you want. But that's not exactly right all the time. `printf '%.35f', 0.123456789012345678901234567890` gives `0.12345678901234567736988623209981597` on my machine. – simbabque Jan 06 '17 at 16:40
  • I tried `sprintf` with `%.4E`, but it gives me 0.0000E+00. I hope to output scientific format. – Woody Lin Jan 06 '17 at 16:55
  • I have also tried `printf` with `%.40f`, but it also gives me 0. – Woody Lin Jan 06 '17 at 17:03
  • It [looks like](http://pdl.perl.org/PDLdocs/Core.html#pdl) PDL uses double-precision floats, which only have a precision of 15-17 significant digits. – ThisSuitIsBlackNot Jan 06 '17 at 22:40
  • PDL calls `gsl_cdf_tdist_P` from C. Is there an easy way to change it to double with more digits? – Woody Lin Jan 07 '17 at 02:49
  • @ThisSuitIsBlackNot R (programing language) can return smaller than 16 digits after decimal. R is calling a C_pt function in C. Do you know which file name it is? Thanks. – Woody Lin Jan 08 '17 at 15:36
  • @simbabque I got the same results as yours. The problem is that `gsl_cdf_tdist_P` is using double-precision binary floating-point format. It seems only store up to 16 digits after decimal. Do you have any idea how to fix this? – Woody Lin Jan 08 '17 at 15:48
  • I don't I'm afraid. If it only has 16 digits than you cannot display any more digits. – simbabque Jan 08 '17 at 16:02

1 Answers1

0

I found an easy solution for this problem. I used gsl_cdf_tdist_Q to get p-values. The p-values are not limited to 16 digits after decimal because they are not remapped p-values like (1-gsl_cdf_tdist_P).

Woody

Woody Lin
  • 11
  • 2