Introduction

Descriptive statistics for PHP. Every sample, distribution and regression is an immutable value object.

Requirements#

The library needs a current PHP version. It has no other requirements and no runtime dependencies.

Installation#

Install the library with Composer.

composer require phpmath/statistics

A first example#

Put your numbers in a Sample and ask for the statistic you need. Each method returns a plain value or a new object. Comments in the examples show the result as var_export() prints it, so a float such as 5 is written as 5.0.

use PHPMath\Statistics\Sample;

$sample = new Sample([2, 4, 4, 4, 5, 5, 7, 9]);

$sample->mean();                    // 5.0
$sample->median();                  // 4.5
$sample->populationVariance();      // 4.0
$sample->sampleStandardDeviation(); // 2.138089935299395

Calling mean() did not change $sample. This is true for every operation in the library.

Where to go next#

Start with the core concepts, or jump straight to the topic you need.