pointStats.pl
Jump to navigation
Jump to search
pointStats.pl is a Perl-based Point Estimation System.
- Context:
- Counter-Example(s):
- See: Average, Standard Deviation.
References
############################################## # pointStat.pl (v1.0) - Calculate some point statistics. # return results in a hash {Average}{Min}{Max}{Median}{SquareSum}{StdDev} # References: http://szabgab.com/talks/fundamentals_of_perl/solution-median.html sub pointStats(@) { my $debug=0 ; die "ERROR: No values were given\n" if (not defined @_) ; my $cardinality = @_ ; my $sum = 0; foreach my $v (@_) {$sum += $v} my $average = $sum / $cardinality ; print "DEBUG: $average = $sum / @_\n" if $debug>=2 ; my @Sorted = sort { $a <=> $b } @_ ; my $min = $Sorted[0] ; my $max = $Sorted[$#Sorted] ; my $median = @Sorted % 2 ? $Sorted[(@Sorted-1)/2] : ($Sorted[@Sorted/2-1]+$Sorted[@Sorted/2])/2 ; my $sqtotal = 0 ; foreach my $v (@Sorted) { $sqtotal += ($average-$v) ** 2 } my $stddev = ($sqtotal / $cardinality) ** 0.5 ; my %Result ; $Result{Cardinality} = $cardinality ; $Result{Sum} = $sum ; $Result{Average} = $average ; $Result{Min} = $min ; $Result{Max} = $max ; $Result{Median} = $median ; $Result{SquareSum} = $sqtotal ; $Result{StdDev} = $stddev ; return %Result }