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$.

Examples

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

show table "" 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 returns the minimum and maximum of the distribution, respectively. An example 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.

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