Math::StdDev - Pure-perl mean and variance computation supporting running/online calculation (Welford's algorithm)
#!/usr/bin/perl -w use Math::StdDev; my $d = new Math::StdDev(); $d->Update(2); $d->Update(3); print $d->mean() . "\t" . $d->sampleVariance(); # or $d->variance()
or
perl -MMath::StdDev -e '$d=new Math::StdDev; $d->Update(10**8+4, 10**8 + 7, 10**8 + 13, 10**8 + 16); print $d->mean() . "\n" . $d->sampleVariance() . "\n"'
This module impliments Welford's online algorithm (see https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance ) Maybe one day in future the two-pass algo could be included, along with Kahan compensated summation... so much math, so little time...
None by default.
Usage is
my $d = new Math::StdDev(); or my $d = new Math::StdDev(1,2,3,4); # Add one or more samples, or a population, right from the start
my $d->Update(123); or my $d->Update(@list_of_scalars);
print $d->mean();
print $d->variance();
(same as variance, but uses n-1 divisor.) Usage is:
print $d->sampleVariance();
This module was written by Chris Drake cdrake@cpan.org.
Copyright (c) 2019 Chris Drake. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.18.2 or, at your option, any later version of Perl 5 you may have available.
To install Math::StdDev, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Math::StdDev
CPAN shell
perl -MCPAN -e shell install Math::StdDev
For more information on module installation, please visit the detailed CPAN module installation guide.