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
views:
67answers:
1
+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
2010-10-11 11:59:55
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
2010-10-11 12:16:29
@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
2010-10-11 12:25:12
I'm actually running linux (Ubuntu and CentOS)
David B
2010-10-11 14:58:49
@David B: You have it with earlier versions of Perl as well?
Joris Meys
2010-10-11 15:29:35
@Joris Meys I don't know. I'm not using earlier versions now and did not use this method before.
David B
2010-10-11 20:39:49
@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
2010-10-12 08:46:37
@Joris Meys: It does return `inf`.
David B
2010-10-12 15:35:20
@David: That rules out platform-dependent issues. So I guess it's really in the implementation itself. Thx for the report.
Joris Meys
2010-10-12 15:43:23