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

acquaintsoft logo
Acquaint Softtech

Hire Laravel developers with AI expertise at $20/hr. Get started in 48 hours.

Visit Acquaint Softtech

The latest

View all →
CPX: The Composer Package Executor for PHP image

CPX: The Composer Package Executor for PHP

Read article
Laravel AI SDK Adds Human-in-the-Loop Tool Approval image

Laravel AI SDK Adds Human-in-the-Loop Tool Approval

Read article
Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals image

Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals

Read article
Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs image

Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs

Read article
Blade Formatting in Laravel Pint image

Blade Formatting in Laravel Pint

Read article
Inertia DevTools Is Now on the Chrome Web Store image

Inertia DevTools Is Now on the Chrome Web Store

Read article