1

有谁知道如何准备数据来绘制 CDF(我有一堆浮点数)?我正计划使用 gnuplot,乍一看,Statistics::Descriptive模块似乎是最合适的,但看起来我可能需要一些帮助。

4

1 回答 1

3

你的问题有点含糊,但这可能会让你开始:

use strict;
use warnings;

use Statistics::Descriptive;
my $stat = Statistics::Descriptive::Full->new;

# Generate some data.
my @data = map { rand 100 } 1 .. 10000;
$stat->add_data(@data);

# Put the data into a frequency distribution with 10 bins.
# The distribution will be represented as a hash, where a hash
# key represents the max value within a bin and the hash value
# is the frequency count for that bin (I'm fudging this a bit;
# see the documentation for more accurate details).
my $n_bins = 10;
my %dist = $stat->frequency_distribution($n_bins);
my @bin_maxes = sort {$a <=> $b} keys %dist;

# Check it out.    
for my $m (@bin_maxes) {
    printf "%6.3f %4d\n", $m, $dist{$m};
}
于 2010-03-10T17:33:20.613 回答