phpOMS/Math/Statistic/Basic.php

64 lines
1.3 KiB
PHP

<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Math\Statistic;
/**
* Basic statistic functions.
*
* @category Framework
* @package phpOMS\DataStorage\Database
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class Basic
{
/**
* Calculate frequency.
*
* Example: ([4, 5, 9, 1, 3])
*
* @param array $values Values
*
* @return array
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function freaquency(array $values) : array
{
$freaquency = [];
if (!($isArray = is_array(reset($values)))) {
$sum = array_sum($values);
}
foreach ($values as $value) {
if ($isArray) {
$freaquency[] = self::freaquency($value);
} else {
$freaquency[] = $value / $sum;
}
}
return $freaquency;
}
}