MathPHP\Statistics\Descriptive::quartilesExclusive PHP Метод

quartilesExclusive() публичный статический Метод

https://en.wikipedia.org/wiki/Quartile 0% is smallest number Q1 (25%) is first quartile (lower quartile, 25th percentile) Q2 (50%) is second quartile (median, 50th percentile) Q3 (75%) is third quartile (upper quartile, 75th percentile) 100% is largest number interquartile_range is the difference between the upper and lower quartiles. (IQR = Q₃ - Q₁) Method used - Use the median to divide the ordered data set into two halves. - If there are an odd number of data points in the original ordered data set, do not include the median (the central value in the ordered list) in either half. - If there are an even number of data points in the original ordered data set, split this data set exactly in half. - The lower quartile value is the median of the lower half of the data. The upper quartile value is the median of the upper half of the data. This rule is employed by the TI-83 calculator boxplot and "1-Var Stats" functions. This is the most basic method that is commonly taught in math textbooks.
public static quartilesExclusive ( array $numbers ) : array
$numbers array
Результат array [ 0%, Q1, Q2, Q3, 100%, IQR ]
    public static function quartilesExclusive(array $numbers) : array
    {
        if (empty($numbers)) {
            return array();
        }
        sort($numbers);
        $length = count($numbers);
        if ($length % 2 == 0) {
            $lower_half = array_slice($numbers, 0, $length / 2);
            $upper_half = array_slice($numbers, $length / 2);
        } else {
            $lower_half = array_slice($numbers, 0, intdiv($length, 2));
            $upper_half = array_slice($numbers, intdiv($length, 2) + 1);
        }
        $lower_quartile = Average::median($lower_half);
        $upper_quartile = Average::median($upper_half);
        return ['0%' => min($numbers), 'Q1' => $lower_quartile, 'Q2' => Average::median($numbers), 'Q3' => $upper_quartile, '100%' => max($numbers), 'IQR' => $upper_quartile - $lower_quartile];
    }