 Quantile - Maple Help

Statistics

 Quantile
 compute quantiles Calling Sequence Quantile(A, p, ds_options) Quantile(X, p, rv_options) Parameters

 A - X - algebraic; random variable or distribution p - algebraic; probability ds_options - (optional) equation(s) of the form option=value where option is one of ignore, method, or weights; specify options for computing the quantile of a data set rv_options - (optional) equation of the form numeric=value; specifies options for computing the quantile of a random variable Description

 • The Quantile function computes the quantile corresponding to the given probability p for the specified random variable or data set.
 • For a real valued random variable X with distribution function $F\left(x\right)$, and any $p$ between 0 and 1, the $p$th quantile of $X$ is defined as $\mathrm{inf}\left\{y|F\left(y\right)\ge p\right\}$. For continuous random variables this is equivalent to the inverse distribution function.
 • For more details on sample quantiles see option method below.
 • The first parameter can be a data set (e.g., a Vector), a Matrix data set, a distribution (see Statistics[Distribution]), a random variable, or an algebraic expression involving random variables (see Statistics[RandomVariable]).
 • The second parameter p is the probability. Computation

 • All computations involving data are performed in floating-point; therefore, all data provided must have type/realcons and all returned solutions are floating-point, even if the problem is specified with exact values.
 • By default, all computations involving random variables are performed symbolically (see option numeric below). Data Set Options

 The ds_options argument can contain one or more of the options shown below. More information for some options is available in the Statistics[DescriptiveStatistics] help page.
 • ignore=truefalse -- This option controls how missing data is handled by the Quantile command. Missing items are represented by undefined or Float(undefined). If ignore=false and A contains missing data, the missing data elements will be considered greater than all present data points. If ignore=true all missing items in A will be ignored. The default value is false.
 • weights=Vector -- Data weights. The number of elements in the weights array must be equal to the number of elements in the original data sample. By default all elements in A are assigned weight $1$.
 • method=integer[1..9] -- Method for calculating the quantiles. Let n denote the number of non-missing elements in A and for $i=1..n$ let ${B}_{i}$ denotes the ith order statistic of A. The first two methods for calculating quantiles are defined as follows.
 1 ${B}_{j}$, where $j=⌊np+1⌋$;
 2 ${B}_{j}$, where $j=⌊np+\frac{1}{2}⌋$;
 9 ${B}_{j}$, where $j=⌊np+1⌋$; unless $np+1$ is an integer, in which case the result is $\frac{{B}_{j-1}}{2}+\frac{{B}_{j}}{2}$.

Note that $p$ is converted to a (hardware or software) floating point value before $j$ is computed, which may cause surprising results due to roundoff.

 The remaining quantiles are calculated in the form ${B}_{j}+\left({B}_{j+1}-{B}_{j}\right)r$, where $j=⌊q⌋$, $r=\mathrm{frac}\left(q\right)$, and $q$ is one of the quantities given below.
 3 $q=np$;
 4 $q=np+\frac{1}{2}$;
 5 $q=\left(n+1\right)p$;
 6 $q=1+\left(n-1\right)p$;
 7 $q=\frac{1}{3}+\left(n+\frac{1}{3}\right)p$;  (default method)
 8 $q=\frac{3}{8}+\left(n+\frac{1}{4}\right)p$. Random Variable Options

 The rv_options argument can contain one or more of the options shown below. More information for some options is available in the Statistics[RandomVariables] help page.
 • numeric=truefalse -- By default, the quantile is computed using exact arithmetic. To compute the quantile numerically, specify the numeric or numeric = true option. Examples

 > $\mathrm{with}\left(\mathrm{Statistics}\right):$

Compute the quantile of the Weibull distribution with parameters $a$ and $b$.

 > $\mathrm{Quantile}\left(\mathrm{Weibull}\left(a,b\right),\frac{1}{3}\right)$
 ${a}{}{{\mathrm{ln}}{}\left(\frac{{3}}{{2}}\right)}^{\frac{{1}}{{b}}}$ (1)

Use numeric parameters.

 > $\mathrm{Quantile}\left(\mathrm{Weibull}\left(3,5\right),\frac{1}{3}\right)$
 ${3}{}{{\mathrm{ln}}{}\left(\frac{{3}}{{2}}\right)}^{{1}}{{5}}}$ (2)
 > $\mathrm{Quantile}\left(\mathrm{Weibull}\left(3,5\right),0.3333333333\right)$
 ${2.50444761563527}$ (3)
 > $\mathrm{Quantile}\left(\mathrm{Weibull}\left(3,5\right),\frac{1}{3},\mathrm{numeric}\right)$
 ${2.50444761563527}$ (4)

Generate a random sample of size 100000 drawn from the above distribution and compute the sample quantile.

 > $A≔\mathrm{Sample}\left(\mathrm{Weibull}\left(3,5\right),{10}^{5}\right):$
 > $\mathrm{Quantile}\left(A,\frac{1}{3}\right)$
 ${2.50274216842899}$ (5)

Compute the standard error of the sample quantile for the normal distribution with parameters 5 and 2.

 > $X≔\mathrm{Normal}\left(5,2\right)$
 ${X}{≔}{\mathrm{Normal}}{}\left({5}{,}{2}\right)$ (6)
 > $B≔\mathrm{Sample}\left(X,{10}^{6}\right):$
 > $\left[\mathrm{Quantile}\left(X,\frac{1}{3},\mathrm{numeric}\right),\mathrm{StandardError}\left[{10}^{6}\right]\left(\mathrm{Quantile},X,\frac{1}{3},\mathrm{numeric}\right)\right]$
 $\left[{4.13854540122573}{,}{0.00259298577070808}\right]$ (7)
 > $\mathrm{Quantile}\left(B,\frac{1}{3}\right)$
 ${4.13691043841748}$ (8)

Create two normal random variables and compute the quantiles of their sum.

 > $X≔\mathrm{RandomVariable}\left(\mathrm{Normal}\left(5,2\right)\right):$
 > $Y≔\mathrm{RandomVariable}\left(\mathrm{Normal}\left(2,5\right)\right):$
 > $\mathrm{Quantile}\left(X+Y,\frac{1}{3}\right)$
 $\frac{\left({7}{}\sqrt{{58}}{+}{58}{}{\mathrm{RootOf}}{}\left({3}{}{\mathrm{erf}}{}\left({\mathrm{_Z}}\right){+}{1}\right)\right){}\sqrt{{58}}}{{58}}$ (9)
 > $\mathrm{Quantile}\left(X+Y,\frac{1}{3},\mathrm{numeric}\right)$
 ${4.68046250585916}$ (10)

Verify this using simulation.

 > $C≔\mathrm{Sample}\left(X+Y,{10}^{6}\right):$
 > $\mathrm{Quantile}\left(C,\frac{1}{3}\right)$
 ${4.68048269533478}$ (11)

Compute the quantile of a weighted data set.

 > $V≔⟨\mathrm{seq}\left(i,i=57..77\right),\mathrm{undefined}⟩:$
 > $W≔⟨2,4,14,41,83,169,394,669,990,1223,1329,1230,1063,646,392,202,79,32,16,5,2,5⟩:$
 > $\mathrm{Quantile}\left(V,\frac{1}{3},\mathrm{weights}=W\right)$
 ${65.5485434888542}$ (12)
 > $\mathrm{Quantile}\left(V,\frac{1}{3},\mathrm{weights}=W,\mathrm{ignore}=\mathrm{true}\right)$
 ${65.5538510125591}$ (13)

Consider the following Matrix data set.

 > $M≔\mathrm{Matrix}\left(\left[\left[3,1130,114694\right],\left[4,1527,127368\right],\left[3,907,88464\right],\left[2,878,96484\right],\left[4,995,128007\right]\right]\right)$
 ${M}{≔}\left[\begin{array}{ccc}{3}& {1130}& {114694}\\ {4}& {1527}& {127368}\\ {3}& {907}& {88464}\\ {2}& {878}& {96484}\\ {4}& {995}& {128007}\end{array}\right]$ (14)

We compute the $\frac{3}{7}$ quantile of each of the columns.

 > $\mathrm{Quantile}\left(M,\frac{3}{7}\right)$
 $\left[\begin{array}{ccc}{3.}& {961.476190476190}& {107756.857142857}\end{array}\right]$ (15) References

 Stuart, Alan, and Ord, Keith. Kendall's Advanced Theory of Statistics. 6th ed. London: Edward Arnold, 1998. Vol. 1: Distribution Theory.
 Hyndman, R.J., and Fan, Y. "Sample Quantiles in Statistical Packages." American Statistician, Vol. 50. (1996): 361-365. Compatibility

 • The A parameter was updated in Maple 16.