Perl包:Statistics_Descriptive 数据统计

模块名: Statistics::Descriptive

使用方法简介

构建对象

1
2
use Statistics::Descriptive
my $stat = Statistics::Descriptive::Full->new();

导入数据

1
2
$stat->add_data(@a); # 导入数组
$stat->add_data($a); # 导入数值

数据处理

1
$stat->sort_data();

数据过滤

1
$stat->set_outlier_filter($code_ref); # 设置一个过滤函数,对数据进行过滤

计算统计指标

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
my $mean = $stat->mean();#平均值
my $variance = $stat->variance();#方差
my $num = $stat->count();#data的数目
my $standard_deviation=$stat->standard_deviation();#标准差
my $sum=$stat->sum();#求和
my $min=$stat->min();#最小值
my $mindex=$stat->mindex();#最小值的index
my $max=$stat->max();#最大值
my $maxdex=$stat->maxdex();#最大值的index
my $range=$stat->sample_range();#最小值到最大值


print "Number of Values = $num\n",
"Mean = $mean\n",
"Variance = $variance\n",
"standard_deviation = $standard_deviation\n",
"sum =$sum\n",
"min =$min\n",
"mindex=$mindex\n",
"max=$max\n",
"maxdex=$maxdex\n",
"range=$range\n";
-------------本文结束感谢您的阅读-------------