Quantile

Quantile[list,q]

gives the q ^(th) quantile of list.

Quantile[list,{q1,q2,}]

gives a list of quantiles q1, q2, .

Quantile[list,q,{{a,b},{c,d}}]

uses the quantile definition specified by parameters a, b, c, d.

Quantile[dist,q]

gives a quantile of the distribution dist.

Details

  • Quantile is also known as value at risk (VaR) or fractile.
  • Quantile[list,q] gives Sort[list,Less][[Max[Ceiling[qLength[list]],1]]].
  • Quantile[{{x1,y1,},{x2,y2,},},q] gives {Quantile[{x1,x2,},q],Quantile[{y1,y2,},q]}.
  • For a list of length n, Quantile[list,q,{{a,b},{c,d}}] depends on x=a+(n+b)q. If x is an integer, the result is s[[x]], where s=Sort[list,Less]. Otherwise, the result is s[[Floor[x]]]+(s[[Ceiling[x]]]-s[[Floor[x]]])(c+dFractionalPart[x]), with the indices taken to be 1 or n if they are out of range.
  • The default choice of parameters is {{0,0},{1,0}}.
  • Common choices of parameters include:
  • {{0, 0}, {1, 0}}inverse empirical CDF (default)
    {{0, 0}, {0, 1}}linear interpolation (California method)
    {{1/2, 0}, {0, 0}}element numbered closest to qn
    {{1/2, 0}, {0, 1}}linear interpolation (hydrologist method)
    {{0, 1}, {0, 1}}meanbased estimate (Weibull method)
    {{1, -1}, {0, 1}}modebased estimate
    {{1/3, 1/3}, {0, 1}}medianbased estimate
    {{3/8, 1/4}, {0, 1}}normal distribution estimate
  • Quantile[list,q] always gives a result equal to an element of list.
  • The same is true whenever d is 0.
  • When d is 1, Quantile is piecewise linear as a function of q.
  • Median[list] is equivalent to Quantile[list,1/2,{{1/2,0},{0,1}}].
  • About 10 different choices of parameters are in use in statistical work.
  • Quantile works with SparseArray objects.
  • Quantile[dist,q] is equivalent to InverseCDF[dist,q].

Examples

open allclose all

Basic Examples  (6)

Find the halfway value (median) of a list:

Find the quarter-way value (lower quartile) of a list:

Lower and upper quartiles:

The q^(th) quantile for a normal distribution:

Quantile function for a continuous univariate distribution:

Quantile function for a discrete univariate distribution:

Scope  (24)

Datasets  (11)

Quantile works with any real numeric quantities:

Find quantiles of elements in each column:

Find multiple quantiles of elements in each column:

Obtain results at any precision:

Compute results for a large vector or matrix:

Compute results for a SparseArray:

Compute results using other parametrizations:

Find quantiles for WeightedData:

Find quantiles for EventData:

Find a quantile for TimeSeries:

The quantile depends only on the values:

Find a quantile for data involving quantities:

Parametric Distributions  (5)

Obtain exact numeric results:

Obtain a machine-precision result:

Obtain a result at any precision for a continuous distribution:

Obtain a symbolic expression for the quantile:

Quantile threads elementwise over lists:

Nonparametric Distributions  (2)

Quantile for nonparametric distributions:

Compare with the value for the underlying parametric distribution:

Plot the quantile for a histogram distribution:

Derived Distributions  (4)

Quantile for a truncated distribution:

Quadratic transformation of an exponential distribution:

Censored distribution:

Quantile for distributions with quantities:

Random Processes  (2)

Quantile function for a random process:

Find a quantile of TemporalData at some time t=0.5:

Find the corresponding quantile function together with all the simulations:

Applications  (7)

A set of equally spaced quantiles divides the values into equal-sized groups:

Calculate a set of quantiles:

Plot the PDF divided according to the values of quantiles into five regions:

Use quantile as a mesh function:

Plot the q^(th) quantile for a list:

The linearly interpolated quantile:

Compute an expectation using quantile :

Use this method in Expectation:

Generate random numbers for a nonuniform distribution by transforming the uniform distribution by the quantile function of the nonuniform distribution:

Compare the histogram of the sample with the probability density function of the desired distribution:

Compute a moving quantile for some data:

Use the window of length .1:

Compute selected quantiles for slices of a collection of paths of a random process:

Choose a few slice times:

Plot the quantiles over these paths:

Compute quantiles for the heights of children in a class:

Properties & Relations  (9)

Use Quantile to find the quartiles of a distribution:

Calculate quartiles directly:

With default parameters, Quantile always returns an element of the list:

Quartiles gives linearly interpolated Quantile values for a list:

InterquartileRange is the difference of linearly interpolated Quantile values for a list:

QuartileDeviation is half the difference of linearly interpolated Quantile values for a list:

QuartileSkewness uses linearly interpolated Quantile values as a skewness measure:

Quantile is equivalent to InverseCDF for distributions:

QuantilePlot plots the quantiles of a list or distribution:

BoxWhiskerChart shows special quantiles for data:

Possible Issues  (2)

Symbolic closed forms do not exist for some distributions:

Numerical evaluation works:

Substitution of invalid values into symbolic outputs gives results that are not meaningful:

It stays unevaluated if passed as an argument:

Neat Examples  (1)

The distribution of Quantile estimates for 20, 100, and 300 samples:

Wolfram Research (2003), Quantile, Wolfram Language function, https://reference.wolfram.com/language/ref/Quantile.html (updated 2007).

Text

Wolfram Research (2003), Quantile, Wolfram Language function, https://reference.wolfram.com/language/ref/Quantile.html (updated 2007).

CMS

Wolfram Language. 2003. "Quantile." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2007. https://reference.wolfram.com/language/ref/Quantile.html.

APA

Wolfram Language. (2003). Quantile. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Quantile.html

BibTeX

@misc{reference.wolfram_2022_quantile, author="Wolfram Research", title="{Quantile}", year="2007", howpublished="\url{https://reference.wolfram.com/language/ref/Quantile.html}", note=[Accessed: 02-June-2023 ]}

BibLaTeX

@online{reference.wolfram_2022_quantile, organization={Wolfram Research}, title={Quantile}, year={2007}, url={https://reference.wolfram.com/language/ref/Quantile.html}, note=[Accessed: 02-June-2023 ]}