perl 计算方差中值平均数 Statistics::Descriptive;

http://search.cpan.org/~shlomif/Statistics-Descriptive-3.0612/lib/Statistics/Descriptive.pm


use Statistics::Descriptive;
my @a=(100,88,77,18,79,96,57,88,65,78,66,99);
my $stat = Statistics::Descriptive::Full->new();
$stat->add_data(@a);
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";

posted on 2017-03-09 16:14  yangyzh  阅读(1977)  评论(0编辑  收藏  举报