Laravel Packages

Calculating Mathematical Statistics in PHP

Published
Calculating Mathematical Statistics in PHP image

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:

use HiFolks\Statistics\Stat;
 
Stat::mean([1, 2, 3, 4, 4]); // 2.8
Stat::mean([-1.0, 2.5, 3.25, 5.75]); // 2.625
 
// The central tendency or typical value of the data
// using the product of the values.
Stat::geometricMean([54, 24, 36], 1); // 36.0
 
Stat::median([1, 3, 5]); // 3
Stat::median([1, 3, 5, 7]); // 4
 
Stat::firstQuartile([
98,90,70,18,92,92,55,83,45,95,88
]); // 55.0
 
Stat::thirdQuartile([
98,90,70,18,92,92,55,83,45,95,88
]); // 92.0
 
$fruits = [
'🍈', '🍈', '🍈', '🍉','🍉','🍉','🍉','🍉','🍌'
];
$freqTable = Freq::frequencies($fruits);
print_r($freqTable);
 
/*
Array
(
[🍈] => 3
[🍉] => 5
[🍌] => 1
)
*/

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.

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Sponsored

masteringlaravel logo
Laravel Code Review

Get expert guidance in a few days with a Laravel code review

Visit Laravel Code Review

The latest

View all →
Building EasyReply: How We Used Laravel to Unify Customer Support image

Building EasyReply: How We Used Laravel to Unify Customer Support

Read article
PostgreSQL Monitoring and Schema Linting for Laravel with Vacuum image

PostgreSQL Monitoring and Schema Linting for Laravel with Vacuum

Read article
PayZephyr: One Payment API for Stripe, Paystack, and PayPal image

PayZephyr: One Payment API for Stripe, Paystack, and PayPal

Read article
Bifrost Turns One With AI Builds and New Workflows image

Bifrost Turns One With AI Builds and New Workflows

Read article
Preview Blade Templates in macOS Finder with Quick Blade image

Preview Blade Templates in macOS Finder with Quick Blade

Read article
Artisan Debugging Commands in Laravel Telescope 5.24.0 image

Artisan Debugging Commands in Laravel Telescope 5.24.0

Read article