Statistics::Descriptive - Module of basic descriptive statistical functions.
use Statistics::Descriptive; $stat = new Statistics::Descriptive; $stat->AddData(1,2,3,4); $mean = $stat->Mean(); $var = $stat->Variance(); $tm = $stat->TrimmedMean(.25);
This module provides basic functions used in descriptive statistics. It has an object oriented design and supports two different modes of data storage and calculations; sparse and full. With the sparse method, none of the data is stored and only a few statistical measures are available. Using the full method, the entire data set is retained and additional functions are available.
Create a new sparse statistics variable.
Adds data to the statistics variable. The cached statistical values are updated automatically.
Returns the number of data items.
Returns the mean of the data.
Returns the sum of the data.
Returns the variance of the data. Division by n-1 is used.
Returns the standard deviation of the data. Division by n-1 is used.
Create a new statistics element. All the data is retained and all defined functions are available.
Synonymous with new.
Adds data to the statistics variable. The only variables which are automatically updated and re-cached are Count, Mean, Sum, Variance, and StandardDeviation. All other previously cached results are deleted since with the addition of new data they are no longer valid.
Count
Mean
Sum
Variance
StandardDeviation
In addition to the functions mentioned in the sparse section, the following functions are also available when using full variables.
Returns a copy of the data.
Returns the maximum value in the data set.
Returns the minimum value in the data set.
Returns the sample range of the data.
Returns the median value of the data.
Returns the harmonic mean of the data.
Returns the geometric mean of the data.
Returns the mode of the data.
TrimmedMean(trim) returns the mean with a fraction trim of entries at each end dropped. TrimmedMean(ltrim,utrim) returns the mean after a fraction ltrim has been removed from the lower end of the data and a fraction utrim has been removed from the upper end of the data.
TrimmedMean(trim)
trim
TrimmedMean(ltrim,utrim)
ltrim
utrim
FrequencyDistribution(partitions) slices the data into partition sets and counts the number of items that fall into each partition. It returns an associative array where the keys are the numerical values of the partitions used. The minimum value of the data set is not a key and the maximum value of the data set is always a key. The number of entries for a particular partition key are the number of items which are greater than the previous partition key and less then or equal to the current partition key. As an example,
FrequencyDistribution(partitions)
partition
$stat->AddData(1,1.5,2,2.5,3,3.5,4); %f = $stat->FrequencyDistribution(2); for (sort {$a <=> $b} keys %f) { print "key = $_, count = $f{$_}\n"; }
prints
key = 2.5, count = 4 key = 4, count = 3
since there are four items less than or equal to 2.5, and 3 items greater than 2.5 and less than 4.
LeastSquaresFit() performs a least squares fit on the data, assuming a domain of 1,2,3... It returns an array of two elements; the value in the zeroth position is the constant (x^0) term and the value in the first position is the coeffiecient of the x^1 term. LeastSquaresFit(@x) uses the values in @x as the domain.
LeastSquaresFit()
LeastSquaresFit(@x)
@x
The Art of Computer Programming, Volume 2, Donald Knuth.
Handbook of Mathematica Functions, Milton Abramowitz and Irene Stegun.
Probability and Statistics for Engineering and the Sciences, Jay Devore.
Copyright (c) 1994,1995 Jason Kastner <jason@wagner.com>. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
April 1995 - Added LeastSquaresFit and FrequencyDistribution.
March 1995 - Released to comp.lang.perl and placed on archive sites.
December 1994 - Complete rewrite after extensive and invaluable e-mail correspondence with Anno Siegel.
December 1994 - Initital concept, released to perl5-porters list.
1 POD Error
The following errors were encountered while parsing the POD:
'=item' outside of any '=over'
=over without closing =back
To install Statistics::Descriptive, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Statistics::Descriptive
CPAN shell
perl -MCPAN -e shell install Statistics::Descriptive
For more information on module installation, please visit the detailed CPAN module installation guide.