Statistics::OnLine(3pm) | User Contributed Perl Documentation | Statistics::OnLine(3pm) |
Statistics::OnLine - Pure Perl implementation of the on-line algorithm to produce statistics
use Statistics::OnLine; my $s = Statistics::OnLine->new; my @data = (1, 2, 3, 4, 5); $s->add_data( @data ); $s->add_data( 6, 7 ); $s->add_data( 8 ); print "count = ",$s->count,"\tmean = ",$s->mean,"\tvariance = ",$s->variance,"\tvariance_n = ", $s->variance_n,"\tskewness = ",$s->skewness,"\tkurtosis = ",$s->kurtosis,"\n"; $s->add_data( ); # does nothing! print "count = ",$s->count,"\tmean = ",$s->mean,"\tvariance = ",$s->variance,"\tvariance_n = ", $s->variance_n,"\tskewness = ",$s->skewness,"\tkurtosis = ",$s->kurtosis,"\n"; $s->add_data( 9, 10 ); print "count = ",$s->count,"\tmean = ",$s->mean,"\tvariance = ",$s->variance,"\tvariance_n = ", $s->variance_n,"\tskewness = ",$s->skewness,"\tkurtosis = ",$s->kurtosis,"\n";
This module implements a tool to perform statistic operations on large datasets which, typically, could not fit the memory of the machine, e.g. a stream of data from the network.
Once instantiated, an object of the class provide an "add_data" method to add data to the dataset. When the computation of some statistics is required, at some point of the stream, the appropriate method can be called. After the execution of the statistics it is possible to continue to add new data. In turn, the object will continue to update the existing data to provide new statistics.
The method return the object itself in order to use it in chaining:
my $v = $s->add_data( 1, 2, 3, 4 )->variance;
Return the object itself in order to use it in chaining:
my $v = $s->clean->add_data( 1, 2, 3, 4 )->variance;
\fract{ \sum_1^n{x_i} }{ n }
\fract{ \sum_1^n{avg - x_i} }{ n - 1 }
\fract{ \sum_1^n{avg - x_i} }{ n }
The conditions in which the system can return errors, using a "die" are:
On-line statistics are based on strong mathematical foundations which transform the standard computations into a sequence of operations that incrementally update with new values the actual ones.
There are some referencence in the web. This documentation suggest to start your investigation from <http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Higher-order_statistics>. The linked page provides other useful references on the foundations of the method.
The module is intended to be used in all the situations in which: (1) the number of data elements could be too large with respect the memory of the system, or (2) the elements arrive at different time stamps and intermediate results are needed.
If the length of the stream is fixed, all the data elements are present in a single place and there is not need for intermediate results, it could be better to use different modules, for instance Statistics::Lite, to make computations.
The reason for this choice is that the module uses a stable approximation, well suited for the use on steams (effectively an on-line algorithm). Using this system on fixed datasets could introduce some (little) approximation.
Francesco Nidito
Copyright 2009 Francesco Nidito. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Statistics::Lite, <http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Higher-order_statistics>
2022-10-13 | perl v5.34.0 |