quantile

quantile, function

def pure quantile(d: ranvar, p: number): number

Returns the pth quantile of the ranvar d; the smallest integer $k$ such that $\mathbf{P}[d \leq k] \geq p$.

Example

table T = with
  [| as P |]
  [| 0.1  |]
  [| 0.5  |]
  [| 0.75 |]
  [| 0.99 |]
  [| 1    |]

show table "" a1b4 with
  T.P as "P"
  quantile(poisson(3), T.P) as "Quantile"

This outputs the following quantile table:

P Quantile
0.10 1
0.50 3
0.75 4
0.99 8
1.00 12

Remarks

quantile(d, 0.5) is called the median of the distribution, and is in general different from the mean.
quantile(d, 0.25) and quantile(d, 0.75) are often referred to as the first and third quantiles, respectively.

Calling quantile with p=0 and p=1 will return the minimum and maximum of the distribution, respectively.
An example of a use case for quantile(d, 1) is to build safeguards on the output d of a probabilistic demand forecast, by comparing quantile(d, 1) with the maximum consumption ever seen on a time window equal to the forecasting horizon, to check whether there is a risk of overforecast.

Errors

Calling quantile with a parameter p outside of $[0, 1]$ is not supported and results in an error message :

‘quantile(d,p)’ : invalid value 2 for p, should be in [0, 1].

User Contributed Notes
0 notes + add a note