2017 © Pedro Peláez
 

library running-stat

PHP implementations of online statistical algorithms

image

wikimedia/running-stat

PHP implementations of online statistical algorithms

  • Saturday, July 28, 2018
  • by wikimedia
  • Repository
  • 15 Watchers
  • 4 Stars
  • 159,716 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 7 % Grown

The README.md

RunningStat

RunningStat computes the central tendency, shape, and extrema of a set of points online, in constant space. It uses a neat one-pass algorithm for calculating variance, described here: https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#On-line_algorithm, (*1)

This particular implementation adapts a sample C++ implementation by John D. Cook to PHP. See also:, (*2)

RunningStat instances can be combined. The resultant RunningStat has the same state it would have had if it had been used to accumulate each point. This property is attractive because it allows separate threads of execution to process a stream in parallel. More importantly, individual points can be accumulated in stages, without loss of fidelity, at intermediate points in the aggregation process. JavaScript profiling samples can be accumulated in the user's browser and be combined with measurements from other browsers on the profiling data aggregator. Functions that are called multiple times in the course of a profiled web request can be accumulated in MediaWiki prior to being transmitted to the profiling data aggregator., (*3)

Usage

Here is how you use it:, (*4)

use Wikimedia\RunningStat;

$rstat = new RunningStat();
foreach ( [
  49.7168, 74.3804,  7.0115, 96.5769, 34.9458,
  36.9947, 33.8926, 89.0774, 23.7745, 73.5154,
  86.1322, 53.2124, 16.2046, 73.5130, 10.4209,
  42.7299, 49.3330, 47.0215, 34.9950, 18.2914,
] as $sample ) {
  $rstat->addObservation( $sample );
}


printf(
  "n = %d; min = %.2f; max = %.2f; mean = %.2f; variance = %.2f; stddev = %.2f\n",
  count( $rstat ),
  $rstat->min,
  $rstat->max,
  $rstat->getMean(),
  $rstat->getVariance(),
  $rstat->getStdDev()
);
// Output:
// n = 20; min = 7.01; max = 96.58; mean = 47.59; variance = 725.71; stddev = 26.94

License

GPL-2.0-or-later, (*5)

The Versions

18/01 2018

v1.2.1

1.2.1.0 https://www.mediawiki.org/wiki/RunningStat

PHP implementations of online statistical algorithms

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.5.9

 

The Development Requires

by Ori Livneh

30/12 2017

v1.2.0

1.2.0.0 https://www.mediawiki.org/wiki/RunningStat

PHP implementations of online statistical algorithms

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.5.9

 

The Development Requires

by Ori Livneh

28/10 2015

v1.1.0

1.1.0.0 https://www.mediawiki.org/wiki/RunningStat

PHP implementations of online statistical algorithms

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.3

 

The Development Requires

by Ori Livneh

27/10 2015

v1.0.0

1.0.0.0 https://www.mediawiki.org/wiki/RunningStat

PHP implementations of online statistical algorithms

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.3

 

The Development Requires

by Ori Livneh