Oihana PHP Arango

percentile.php

Table of Contents

Functions

percentile()  : string
Return the nth percentile of the values in an array.

Functions

percentile()

Return the nth percentile of the values in an array.

percentile(mixed $numArray, int $position, string|null $method) : string

This helper wraps the ArangoDB AQL function PERCENTILE(numArray, n, method) which returns the nth percentile of all values in the given array. The position must be between 0 (excluded) and 100 (included).

Example AQL usage:

PERCENTILE([1, 2, 3, 4, 5], 50)                  // returns 3 (50th percentile)
PERCENTILE([1, 2, 3, 4, 5], 25)                  // returns 2 (25th percentile)
PERCENTILE([1, 2, 3, 4, 5], 75)                  // returns 4 (75th percentile)
PERCENTILE([1, 2, 3, 4, 5], 50, "interpolation") // returns 3 (with interpolation)
Parameters
$numArray : mixed

Array expression containing numeric values (null values are ignored).

$position : int

The percentile position (must be between 0 and 100).

$method : string|null

Optional method: "rank" (default) or "interpolation".

Tags
example
use function oihana\arango\db\functions\numerics\percentile;

$expr = percentile('[1, 2, 3, 4, 5]', 50);
// Produces: 'PERCENTILE([1, 2, 3, 4, 5], 50)'

$expr = percentile('[1, 2, 3, 4, 5]', 50, 'interpolation');
// Produces: 'PERCENTILE([1, 2, 3, 4, 5], 50, "interpolation")'
see
https://docs.arangodb.com/stable/aql/functions/numeric/#percentile
median()

For the 50th percentile.

average()

For calculating the mean.

since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

On this page

Search results