Calculating Mathematical Statistics in PHP

Packages

February 9th, 2022

Calculating Mathematical Statistics in PHP

Hi-Folks/statistics is a PHP package that provides functions for calculating mathematical statistics of numeric data. This package includes functions that can calculate things like mean, median, quartile calculations, and specialized calculations like geometric mean:

1use HiFolks\Statistics\Stat;
2 
3Stat::mean([1, 2, 3, 4, 4]); // 2.8
4Stat::mean([-1.0, 2.5, 3.25, 5.75]); // 2.625
5 
6// The central tendency or typical value of the data
7// using the product of the values.
8Stat::geometricMean([54, 24, 36], 1); // 36.0
9 
10Stat::median([1, 3, 5]); // 3
11Stat::median([1, 3, 5, 7]); // 4
12 
13Stat::firstQuartile([
14 98,90,70,18,92,92,55,83,45,95,88
15]); // 55.0
16 
17Stat::thirdQuartile([
18 98,90,70,18,92,92,55,83,45,95,88
19]); // 92.0
20 
21$fruits = [
22 '🍈', '🍈', '🍈', '🍉','🍉','🍉','🍉','🍉','🍌'
23];
24$freqTable = Freq::frequencies($fruits);
25print_r($freqTable);
26 
27/*
28Array
29(
30 [🍈] => 3
31 [🍉] => 5
32 [🍌] => 1
33)
34*/

The above is just a sample of the various functions provided in this package. The readme has good documentation and examples of using all of them. You can learn more about this package, get full installation instructions, and view the source code on GitHub.

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.