> ## Documentation Index
> Fetch the complete documentation index at: https://docs.activeviam.com/llms.txt
> Use this file to discover all available pages before exploring further.

# quantile()

<span id="atoti.agg.quantile" />

> @overload<br />
> atoti.agg.quantile(<br />
>     *operand*: LevelOrVariableColumnConvertible,<br />
>     /,<br />
>     *q*: \_Quantile,<br />
>     \*,<br />
>     *mode*: [Literal](https://docs.python.org/3/library/typing.html#typing.Literal)\['simple', 'centered', 'inc', 'exc'] = `'inc'`,<br />
>     *interpolation*: [Literal](https://docs.python.org/3/library/typing.html#typing.Literal)\['linear', 'higher', 'lower', 'nearest', 'midpoint'] = `'linear'`,<br />
> ) → MeasureDefinition

> @overload<br />
> atoti.agg.quantile(<br />
>     *operand*: VariableMeasureConvertible,<br />
>     /,<br />
>     *q*: \_Quantile,<br />
>     \*,<br />
>     *mode*: [Literal](https://docs.python.org/3/library/typing.html#typing.Literal)\['simple', 'centered', 'inc', 'exc'] = `'inc'`,<br />
>     *interpolation*: [Literal](https://docs.python.org/3/library/typing.html#typing.Literal)\['linear', 'higher', 'lower', 'nearest', 'midpoint'] = `'linear'`,<br />
>     *scope*: [CumulativeScope](./atoti.scope.CumulativeScope#atoti.CumulativeScope) | [SiblingsScope](./atoti.scope.SiblingsScope#atoti.SiblingsScope) | [OriginScope](./atoti.scope.OriginScope#atoti.OriginScope),<br />
> ) → MeasureDefinition

Return a measure equal to the requested quantile of the passed operand across the specified scope.

Here is how to obtain the same behavior as [these standard quantile calculation methods](https://en.wikipedia.org/wiki/Quantile#Estimating_quantiles_from_a_sample):

* R-1: `mode="centered"` and `interpolation="lower"`
* R-2: `mode="centered"` and `interpolation="midpoint"`
* R-3: `mode="simple"` and `interpolation="nearest"`
* R-4: `mode="simple"` and `interpolation="linear"`
* R-5: `mode="centered"` and `interpolation="linear"`
* R-6 (similar to Excel’s `PERCENTILE.EXC`): `mode="exc"` and `interpolation="linear"`
* R-7 (similar to Excel’s `PERCENTILE.INC`): `mode="inc"` and `interpolation="linear"`
* R-8 and R-9 are not supported

The formulae given for the calculation of the quantile index assume a 1-based indexing system.

### Parameters

<h4 id="atoti.agg.quantile.operand">
  *operand*
</h4>

The operand to get the quantile of.

<h4 id="atoti.agg.quantile.q">
  *q*
</h4>

The quantile to take.
For instance, `0.95` is the 95th percentile and `0.5` is the median.

<h4 id="atoti.agg.quantile.mode">
  *mode*
</h4>

The method used to calculate the index of the quantile.
Available options are, when searching for the *q* quantile of a vector `X`:

* `simple`: `len(X) * q`
* `centered`: `len(X) * q + 0.5`
* `exc`: `(len(X) + 1) * q`
* `inc`: `(len(X) - 1) * q + 1`

<h4 id="atoti.agg.quantile.interpolation">
  *interpolation*
</h4>

If the quantile index is not an integer, the interpolation decides what value is returned.
The different options are, considering a quantile index `k` with `i < k < j` for a sorted vector `X`:

* `linear`: `v = X[i] + (X[j] - X[i]) * (k - i)`
* `lower`: `v = X[i]`
* `higher`: `v = X[j]`
* `nearest`: `v = X[i]` or `v = X[j]` depending on which of `i` or `j` is closest to `k`
* `midpoint`: `v = (X[i] + X[j]) / 2`

<h4 id="atoti.agg.quantile.scope">
  *scope*
</h4>

The [`aggregation scope`](./atoti.scope#module-atoti.scope).
