views:

67

answers:

1
use strict;
use warnings;
use Statistics::Descriptive;
use 5.012;

my @data = ( -2, 7, 7, 4, 18, -5 );
my $stat = Statistics::Descriptive::Full->new();
$stat->add_data(@data);
say ($stat->percentile(100) // "undef"); # return 18. OK.
say ($stat->percentile(0) // "undef"); # return undef instead of "-inf". see doc below

Statistics::Descriptive doc.

+3  A: 

Same outcome on ActiveState 5.12.2 64-bit on a Windows platform. You answered your own question: it does not work as documented.

#!/usr/bin/perl -w
use strict;
use warnings;
use Statistics::Descriptive;
use Math::Bigint;

use 5.012;

my @data = ( -2, 7, 7, 4, 18, -5 );
my $stat = Statistics::Descriptive::Full->new();
$stat->add_data(@data);
say(Math::BigInt->is_inf($stat->percentile(0)));

returns 0

Edit : as rafl points out, on a Windows system perl -e "print(9**9**9);" will give 1.#INF instead of inf. As inf apparently isn't implemented yet in my version, the Statistics package won't be able to return inf and returns undefined instead.

Edit2 : As it turns out OP works on Linux and can return inf, the error is probably inherent to the Statistics::Descriptive package.

Joris Meys
Note that the C library on win32 formats a double containing Infinity or Not A Number as `1.#INF`, `-1.#INF`, `1.#QNAN`, and `-1.#IND`, instead of `inf`, `-inf`, `nan`, and `-nan`, as you might expect from most Unix platforms. `Math::BigInt`s `is_inf` and `is_nan` methods don't cope with that yet (although work is underway to fix this both in the perl core and `Math::BigInt`).
rafl
@rafl : thanks for the clarification. I noticed already, and I'm quite sure that OP runs a Windows as well. That is more than likely why the percentile function gives this result. But unless OP states what his setup is, this cannot be said for sure.
Joris Meys
I'm actually running linux (Ubuntu and CentOS)
David B
@David B: You have it with earlier versions of Perl as well?
Joris Meys
@Joris Meys I don't know. I'm not using earlier versions now and did not use this method before.
David B
@David B: Just do the test: if `perl -e "print(9**9**9);"` doesn't return **inf**, then that is the cause of the problem. Otherwise, it's something else in the implementation of the Statistics module.
Joris Meys
@Joris Meys: It does return `inf`.
David B
@David: That rules out platform-dependent issues. So I guess it's really in the implementation itself. Thx for the report.
Joris Meys