Skip Menu |

This queue is for tickets about the Statistics-Descriptive CPAN distribution.

Report information
The Basics
Id: 31394
Status: rejected
Priority: 0/
Queue: Statistics-Descriptive

People
Owner: Nobody in particular
Requestors: rayslinky [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 2.6
Fixed in: (no value)



Subject: multiple objects foobars percentile
When using multiple Statistics::Descriptive objects, results of of the percentile sub are unpredictable. === BEGIN EXAMPLE === #!/usr/bin/perl use Statistics::Descriptive; $s1 = Statistics::Descriptive::Full->new(); $s2 = Statistics::Descriptive::Full->new(); for (1..10) { $s1->add_data($_); $s2->add_data($_); } $s2->add_data($_) for (11..20); printf "%s\t%s\t%s\n", "perc", "set 1", "set 2"; printf "%s\t%d\t%d\n", $_ . "%", $s1->percentile($_), $s2->percentile($_) foreach (25, 75); === END EXAMPLE === I would expect this to produce 3 and 8 for s1 and 5 and 15 for s2, however it generates: perc set 1 set 2 25% 3 2 75% 8 7
From: se_misc [...] hotmail.com
Something is weired with the printf at the end... Try the following: #!/usr/bin/perl use Statistics::Descriptive; $s1 = Statistics::Descriptive::Full->new(); $s2 = Statistics::Descriptive::Full->new(); for (1..10) { $s1->add_data($_); $s2->add_data($_); } $s2->add_data($_) for (11..20); printf " %s\t%s\t%s\n", "perc", "set 1", "set 2"; foreach $i (25, 75) { print "Correct: " . $i . "%\t"; print $s1->percentile($i) . "\t"; print $s2->percentile($i) . "\n"; } printf "Error: %s\t%d\t%d\n", $_ . "%", $s1->percentile($_), $s2->percentile($_) foreach (25, 75); which yields: perc set 1 set 2 Correct: 25% 3 5 Correct: 75% 8 15 Error: 25% 3 2 Error: 75% 8 7
Hi! Thanks for your report This is not a bug, as in one place ->percentile is evaluated in scalar context and the other place in list context, and it returns a different number of results in each time. Here is a corrected script that does not exhibit this problem: {{{{{{{{{{{{{{{ #!/usr/bin/perl use strict; use warnings; use Statistics::Descriptive; my $s1 = Statistics::Descriptive::Full->new(); my $s2 = Statistics::Descriptive::Full->new(); for (1..10) { $s1->add_data($_); $s2->add_data($_); } $s2->add_data($_) for (11..20); printf " %s\t%s\t%s\n", "perc", "set 1", "set 2"; foreach my $i (25, 75) { print "Correct: " . $i . "%\t"; print scalar($s1->percentile($i)) . "\t"; print scalar($s2->percentile($i)) . "\n"; } foreach my $i (25, 75) { printf "Error: %s\t%d\t%d\n", ($i . "%"), scalar($s1->percentile($i)), scalar($s2->percentile($i)) ; } }}}}}}}}}}}}}}} I'll close this bug once I have the appropriate permissions. Regards, -- Shlomi Fish
As per my previous comment, this bug is closed, because it was a matter of Perl's scalar/list context, and not a real bug in S-D.