Statistics-Lite-3.62/0000770060175106017510000000000012614575250013363 5ustar BrianBrianStatistics-Lite-3.62/Changes0000770060175106017510000000277112614575171014672 0ustar BrianBrianRevision history for Perl extension Statistics::Lite. 3.62 Fri 29 Oct 2015 22:05:05 PM PDT - Improved documentation and better organized tests, from Baldur Kristinsson 3.61 Fri 27 Feb 2015 01:14:44 PM PST - Upgraded ExtUtils::MakeMaker and repackaged (no functionality changes) 3.6 Sun 22 Feb 2015 09:59:02 PM PST - Added github repo to dist metadata and pod 3.5 Sat 21 Feb 2015 11:38:52 PM PST - Exclude undefined values, per CPAN bug # 50448 3.4 Mon Feb 16 10:04:50 2015 - documentation fixes and additional tests - now version controlled! https://github.com/brianary/Statistics-Lite 3.3 Fri Feb 13 10:03:45 2015 - added license info 3.2 Sun Jun 24 11:13:00 2007 - updated tests 3.1 - fixed and renamed biased (population) versions - added unbiased versions 3.00 Sat Mar 3 16:48:00 2007 - after much delay, stddev has been restored to the sample or biased version of the formula; if you need the unbiased version, use stddev(0,@data) - added frequencies() function from Nathan Haigh ... time passed, people laughed and loved and sat, and we all learned something about the true meaning of New Year's Day ... 1.02 Fri Nov 4 12:25:00 2005 - expanded explanation of limitations 1.01 Thu Jan 10 14:59:52 2002 - bugfix version 1.00 Thu Jan 10 14:25:38 2002 - fixed median algorithm 0.05 Mon Jan 22 08:13:00 2001 - various optimizations 0.01 Thu Sep 21 09:56:43 2000 - original version; created by h2xs 1.19 Statistics-Lite-3.62/Lite.pm0000770060175106017510000002023412614575207014624 0ustar BrianBrianpackage Statistics::Lite; use strict; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); require Exporter; $VERSION = '3.62'; @ISA = qw(Exporter); @EXPORT = (); @EXPORT_OK = qw(min max range sum count mean median mode variance stddev variancep stddevp statshash statsinfo frequencies); %EXPORT_TAGS= ( all => [ @EXPORT_OK ], funcs => [qw], stats => [qw], ); sub definedvals { return grep{defined}@_; } sub count { return scalar definedvals @_; } sub min { my @data = definedvals @_; return unless @data; return $data[0] unless @data > 1; my $min= shift @data; foreach(@data) { $min= $_ if $_ < $min; } return $min; } sub max { my @data = definedvals @_; return unless @data; return $data[0] unless @data > 1; my $max= shift @data; foreach(@data) { $max= $_ if $_ > $max; } return $max; } sub range { my @data = definedvals @_; return unless @data; return 0 unless @data > 1; return abs($data[1]-$data[0]) unless @data > 2; my $min= shift @data; my $max= $min; foreach(@data) { $min= $_ if $_ < $min; $max= $_ if $_ > $max; } return $max - $min; } sub sum { my @data = definedvals @_; return unless @data; return $data[0] unless @data > 1; my $sum; foreach(@data) { $sum+= $_; } return $sum; } sub mean { my @data = definedvals @_; return unless @data; return $data[0] unless @data > 1; return sum(@data)/scalar(@data); } sub median { my @data = definedvals @_; return unless @data; return $data[0] unless @data > 1; @data= sort{$a<=>$b}@data; return $data[$#data/2] if @data&1; my $mid= @data/2; return ($data[$mid-1]+$data[$mid])/2; } sub mode { my @data = definedvals @_; return unless @data; return $data[0] unless @data > 1; my %count; foreach(@data) { $count{$_}++; } my $maxhits= max(values %count); foreach(keys %count) { delete $count{$_} unless $count{$_} == $maxhits; } return mean(keys %count); } sub variance { my @data = definedvals @_; return unless @data; return 0 unless @data > 1; my $mean= mean @data; return (sum map { ($_ - $mean)**2 } @data) / $#data; } sub variancep { my @data = definedvals @_; return unless @data; return 0 unless @data > 1; my $mean= mean @data; return (sum map { ($_ - $mean)**2 } @data) / ( $#data +1 ); } sub stddev { my @data = definedvals @_; return unless @data; return 0 unless @data > 1; return sqrt variance @data; } sub stddevp { my @data = definedvals @_; return unless @data; return 0 unless @data > 1; return sqrt variancep @data; } sub statshash { my @data = definedvals @_; return unless @data; return ( count => 1, min => $data[0], max => $data[0], range => 0, sum => $data[0], mean => $data[0], median => $data[0], mode => $data[0], variance => 0, stddev => 0, variancep => 0, stddevp => 0 ) unless @data > 1; my $count= scalar(@data); @data= sort{$a<=>$b}@data; my $median; if(@data&1) { $median= $data[$#data/2]; } else { my $mid= @data/2; $median= ($data[$mid-1]+$data[$mid])/2; } my $sum= 0; my %count; foreach(@data) { $sum+= $_; $count{$_}++; } my $mean= $sum/$count; my $maxhits= max(values %count); foreach(keys %count) { delete $count{$_} unless $count{$_} == $maxhits; } return ( count => $count, min => $data[0], max => $data[-1], range => ($data[-1] - $data[0]), sum => $sum, mean => $mean, median => $median, mode => mean(keys %count), variance => variance(@data), stddev => stddev(@data), variancep => variancep(@data), stddevp => stddevp(@data) ); } sub statsinfo { my %stats= statshash(@_); return <<"."; min = $stats{min} max = $stats{max} range = $stats{range} sum = $stats{sum} count = $stats{count} mean = $stats{mean} median = $stats{median} mode = $stats{mode} variance = $stats{variance} stddev = $stats{stddev} variancep = $stats{variancep} stddevp = $stats{stddevp} . } sub frequencies { my @data = definedvals @_; return unless @data; return ( $data[0], 1 ) unless @data > 1; my %count; foreach(@data) { $count{$_}++; } return %count; } 1; __END__ =head1 NAME Statistics::Lite - Small stats stuff. =head1 SYNOPSIS use Statistics::Lite qw(:all); $min= min @data; $mean= mean @data; %data= statshash @data; print "sum= $data{sum} stddev= $data{stddev}\n"; print statsinfo(@data); =head1 DESCRIPTION This module is a lightweight, functional alternative to larger, more complete, object-oriented statistics packages. As such, it is likely to be better suited, in general, to smaller data sets. This is also a module for dilettantes. When you just want something to give some very basic, high-school-level statistical values, without having to set up and populate an object first, this module may be useful. =head2 NOTE This module implements standard deviation and variance calculated by both the unbiased and biased estimators. =head1 FUNCTIONS =over 4 =item C, C, C, C, C Returns the minimum value, maximum value, range (max - min), sum, or count of values in C<@data>. Undefined values are ignored. C simply returns C. B that this module does B ignore undefined values in your data; instead, those are B. =item C, C, C Calculates the mean, median, or mode average of the values in C<@data>. Undefined values are ignored. (In the event of ties in the mode average, their mean is returned.) =item C, C Returns the standard deviation or variance of C<@data> for a sample (same as Excel's STDEV). This is also called the Unbiased Sample Variance and involves dividing the sample's squared deviations by N-1 (the sample count minus 1). The standard deviation is just the square root of the variance. =item C, C Returns the standard deviation or variance of C<@data> for the population (same as Excel's STDEVP). This involves dividing the squared deviations of the population by N (the population size). The standard deviation is just the square root of the variance. =item C Returns a hash whose keys are the names of all the functions listed above, with the corresponding values, calculated for the data set. =item C Returns a string describing the data set, using the values detailed above. =item C Returns a hash. The keys are the distinct values in the data set, and the values are the number of times that value occurred in the data set. =back =head2 Import Tags The C<:all> import tag imports all exportable functions from this module into the current namespace (use with caution). More specifically, these functions are the following: C, C, C, C, C, C, C, C, C, C, C, C, C, C, and C. To import the statistical functions, use the import tag C<:funcs>. This imports all of the above-mentioned functions, except for C, C, and C. Use C<:stats> to import C and C. =head1 REPOSITORY L =head1 AUTHOR Brian Lalonde Ebrian@webcoder.infoE, C, C, C, C, additional motivation by Nathan Haigh, with kind support from Alexander Zangerl. The project lives at https://github.com/brianary/Statistics-Lite =head1 COPYRIGHT AND LICENSE Copyright 2000 Brian Lalonde Ebrian@webcoder.infoE, Nathan Haigh, Alexander Zangerl, and Ton Voon. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut =head1 SEE ALSO perl(1). =cut Statistics-Lite-3.62/Makefile.PL0000770060175106017510000000135412614445357015347 0ustar BrianBrianuse ExtUtils::MakeMaker; my $mm_ver = $ExtUtils::MakeMaker::VERSION; if ($mm_ver =~ /_/) { # developer release $mm_ver = eval $mm_ver; die $@ if $@; } WriteMakefile( NAME => 'Statistics::Lite', AUTHOR => 'Brian Lalonde (brian@webcoder.info)', LICENSE => 'perl', VERSION_FROM => 'Lite.pm', ABSTRACT_FROM => 'Lite.pm', ($mm_ver <= 6.45 ? () : (META_MERGE => { 'meta-spec' => { version => 2 }, resources => { repository => { type => 'git', web => 'https://github.com/brianary/Statistics-Lite', url => 'https://github.com/brianary/Statistics-Lite.git', }, }, }) ), ); Statistics-Lite-3.62/MANIFEST0000770060175106017510000000065712614575250014527 0ustar BrianBrianChanges Lite.pm Makefile.PL MANIFEST META.yml Module meta-data (added by MakeMaker) t/00_use_ok.t t/01_functional_basic.t t/02_functional_negative.t t/03_functional_undefs.t t/04_functional_unbiased.t t/05_functional_population.t t/06_statshash_basic.t t/07_statshash_more.t t/08_statshash_var_freq.t META.json Module JSON meta-data (added by MakeMaker) Statistics-Lite-3.62/META.json0000770060175106017510000000201012614575250015000 0ustar BrianBrian{ "abstract" : "Small stats stuff.", "author" : [ "Brian Lalonde (brian@webcoder.info)" ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 6.98, CPAN::Meta::Converter version 2.142060", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Statistics-Lite", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } } }, "release_status" : "stable", "resources" : { "repository" : { "type" : "git", "url" : "https://github.com/brianary/Statistics-Lite.git", "web" : "https://github.com/brianary/Statistics-Lite" } }, "version" : "3.62" } Statistics-Lite-3.62/META.yml0000770060175106017510000000106112614575247014643 0ustar BrianBrian--- abstract: 'Small stats stuff.' author: - 'Brian Lalonde (brian@webcoder.info)' build_requires: ExtUtils::MakeMaker: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 6.98, CPAN::Meta::Converter version 2.142060' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Statistics-Lite no_index: directory: - t - inc resources: repository: https://github.com/brianary/Statistics-Lite.git version: '3.62' Statistics-Lite-3.62/t/0000770060175106017510000000000012614575247013634 5ustar BrianBrianStatistics-Lite-3.62/t/00_use_ok.t0000770060175106017510000000040312614445357015603 0ustar BrianBrianuse Test::More tests => 1; BEGIN { diag( "Beginning Statistics::Lite tests in $^O with Perl $], $^X" ); use_ok( 'Statistics::Lite' ) || print "ERROR: Could not load module\n"; } diag( "Testing Statistics::Lite $Statistics::Lite::VERSION" ); Statistics-Lite-3.62/t/01_functional_basic.t0000770060175106017510000000143612614445357017631 0ustar BrianBrian#!/usr/bin/perl use strict; use warnings; use Test::More tests => 11; BEGIN { use_ok( 'Statistics::Lite', ':all' ); } # Basic functional interface is(min(1,2,3), 1, "call min - functional interface"); is(max(1,2,3), 3, "call max - functional interface"); is(range(1,2,3), 2, "call range - functional interface"); is(sum(1,2,3), 6, "call sum - functional interface"); is(count(1,2,3), 3, "call count - functional interface"); is(count(undef,1,2,3), 3, "call count with undef - functional interface"); is(mean(1,2,3), 2, "call mean - functional interface"); is(median(1,2,3), 2, "call median - functional interface"); is(median(2,4,6,8), 5, "call median with even number of values - functional interface"); is(mode(1,2,3), 2, "call mode - functional interface"); Statistics-Lite-3.62/t/02_functional_negative.t0000770060175106017510000000055112614445357020350 0ustar BrianBrian#!/usr/bin/perl use strict; use warnings; use Test::More tests => 4; BEGIN { use_ok( 'Statistics::Lite', ':all' ); } # basic functional interface continued: negative numbers is(min(1,-5,8), -5, "call min with negative numbers" ); is(range(-6,-9), 3, "call range with negative values" ); is(range(6,-9), 15, "call range with data crossing 0" ); Statistics-Lite-3.62/t/03_functional_undefs.t0000770060175106017510000000262212614445357020034 0ustar BrianBrian#!/usr/bin/perl use strict; use warnings; use Test::More tests => 20; BEGIN { use_ok( 'Statistics::Lite', ':all' ); } # undef checking # is(min(undef), undef, "call min with only single undefined value" ); is(max(undef), undef, "call max with only single undefined value" ); is(min(), undef, "call min without values" ); is(max(), undef, "call max without values" ); is(min(6,undef,10), 6, "call min with undefined value" ); is(max(-6,-10,undef), -6, "call max with undefined value" ); is(min(undef, 7, -5), -5, "call min with initial undefined value" ); is(max(undef, 7, -5), 7, "call max with initial undefined value" ); is(min(undef,undef,undef), undef, "call min with only undefined values" ); is(max(undef,undef,undef), undef, "call max with only undefined values" ); is(count(undef, 7, -5), 2, "call count with undefined value" ); is(sum(undef, 7, -5), 2, "call sum with undefined value" ); is(mean(undef, 7, -5), 1, "call mean with undefined value" ); is(count(undef,undef,undef), 0, "call count with only undefined values" ); is(mean(undef,undef,undef), undef, "call mean with only undefined values" ); is(range(6,9,undef), 3, "call range with undefined value" ); is(range(undef,6,9), 3, "call range with leading undefined value" ); is(range(undef,undef,undef,7), 0, "call range with single defined value" ); is(range(undef,undef,undef), undef, "call range with only undefined values" ); Statistics-Lite-3.62/t/04_functional_unbiased.t0000770060175106017510000000101112614445357020332 0ustar BrianBrian#!/usr/bin/perl use strict; use warnings; use Test::More tests => 6; BEGIN { use_ok( 'Statistics::Lite', ':all' ); } # unbiased sample test my @values = (3, -10, 8, undef, 7, undef, 8, 3, 6, 3); is(mean(@values), 3.5, "call unbiased sample set mean" ); is(median(@values), 4.5, "call unbiased sample set median" ); is(mode(@values), 3, "call unbiased sample set mode" ); is(variance(1,2,3), 1, "call unbiased sample set variance"); is(stddev(1,2,3), 1, "call unbiased sample set standard deviation"); Statistics-Lite-3.62/t/05_functional_population.t0000770060175106017510000000044212614445357020742 0ustar BrianBrian#!/usr/bin/perl use strict; use warnings; use Test::More tests => 3; BEGIN { use_ok( 'Statistics::Lite', ':all' ); } # population sample test is(variancep(2,4,2,4), 1, "call variancep - functional interface"); is(stddevp(2,4,2,4), 1, "call stddevp - functional interface"); Statistics-Lite-3.62/t/06_statshash_basic.t0000770060175106017510000000140412614445357017471 0ustar BrianBrian#!/usr/bin/perl use strict; use warnings; use Test::More tests => 11; BEGIN { use_ok( 'Statistics::Lite', ':all' ); } my %stats= statshash(1,2,3); is($stats{min}, 1, "call min - hash-based interface"); is($stats{max}, 3, "call max - hash-based interface"); is($stats{range}, 2, "call range - hash-based interface"); is($stats{sum}, 6, "call sum - hash-based interface"); is($stats{count}, 3, "call count - hash-based interface"); is($stats{mean}, 2, "call mean - hash-based interface"); is($stats{median}, 2, "call median - hash-based interface"); is($stats{mode}, 2, "call mode - hash-based interface"); is($stats{variance}, 1, "call variance - hash-based interface"); is($stats{stddev}, 1, "call stddev - hash-based interface"); Statistics-Lite-3.62/t/07_statshash_more.t0000770060175106017510000000066012614445357017356 0ustar BrianBrian#!/usr/bin/perl use strict; use warnings; use Test::More tests => 5; BEGIN { use_ok( 'Statistics::Lite', ':all' ); } # statshash: a tiny bit more substantial data set my %stats = statshash(0..10,1); is($stats{sum},56,"call sum - hash-based"); is($stats{mean},4+2/3,"call mean - hash-based"); is($stats{variance},11+1/3,"call variance - hash-based"); is($stats{variancep},10.3+8/90,"call variancep - hash-based"); Statistics-Lite-3.62/t/08_statshash_var_freq.t0000770060175106017510000000112612614445357020220 0ustar BrianBrian#!/usr/bin/perl use strict; use warnings; use Test::More tests => 7; BEGIN { use_ok( 'Statistics::Lite', ':all' ); } # statshash: variance and frequencies my %stats= statshash(2,4,2,4); ok($stats{variancep}, "call variancep - hash-based interface"); ok($stats{stddevp}, "call stddevp - hash-based interface"); %stats= frequencies(1,2,3,3); is($stats{1}, 1, "frequencies matched correctly for 1"); is($stats{2}, 1, "frequencies matched correctly for 2"); is($stats{3}, 2, "frequencies matched correctly for 3"); is($stats{4}, undef, "frequencies matched correctly for 4");