Statistics - Maple Programming Help

Home : Support : Online Help : Statistics and Data Analysis : Statistics Package : Quantities : Statistics/OrderStatistic

Statistics

 OrderStatistic
 compute order statistics

 Calling Sequence OrderStatistic(A, j, ds_options) OrderStatistic(X, j, n, rv_options)

Parameters

 A - X - algebraic; random variable or distribution j - integer; order n - posint; sample size ds_options - (optional) equation(s) of the form option=value where option is one of ignore, inplace, or ordering; specify options for computing an OrderStatistic of a data set rv_options - (optional) equation of the form numeric=value; specifies options for computing an OrderStatistic of a random variable

Description

 • For a data set A the OrderStatistic function computes the jth order statistic of A. For a random variable X, the OrderStatistic commands returns a new random variable which has the same distribution as the jth order statistic of an n-element sample drawn from the same distribution as X. This new random variable is independent of other random variables, including random variables created by other calls to OrderStatistic.
 • The first parameter can be a data set (given as e.g. a Vector), a distribution (see Statistics[Distribution]), a random variable, or an algebraic expression involving random variables (see Statistics/RandomVariable).
 • The second parameter j is the order. If j is a negative integer, then the $\left(n+j+1\right)$th order statistic is calculated.
 • If the first parameter is a random variable or a distribution, the third parameter specifies the sample size.

Computation

 • By default, all computations involving random variables are performed symbolically (see option numeric below).
 • 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.

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 OrderStatistic command. Missing items are represented by undefined or Float(undefined). So, if ignore=false and A contains missing data, the OrderStatistic command can behave in an unexpected manner. If ignore=true all missing items in A will be considered greater than all other data; that is, they become higher order statistics. The default value is false.
 • inplace=truefalse -- In order to compute an order statistic of a data set, Maple normally makes a copy of that data set and rearranges the items to make it, in some sense, closer to being sorted. (In particular, when it computes the jth order statistic, then all elements before the jth element of this copy of A will be less than or equal to A[j], and all elements after it will be greater or equal). If A has the correct data type (details mentioned later), the ignore option is false (or not included), and the inplace option is set to true, then Maple will not make this copy and apply the reordering to A itself. If A does not have the appropriate data type, or the ignore option is specified, then the inplace option is ignored.
 The data sample A can use the inplace option if it is a Vector or a one-dimensional Array, and it has its datatype option set to float. More precisely, if the setting of the Digits variable is less than or equal to evalhf(Digits) (this is the default), then its datatype option needs to be float[8]; otherwise it needs to be sfloat. This is the setting you get when you specify the option datatype=float to the Vector or Array procedure.
 • ordering=procedure -- By default, OrderStatistic will deal only with numeric data, and it will compute the jth order statistic according to the numeric ordering. If you need the jth order statistic according to a different ordering, you can get it by specifying an ordering procedure using the ordering=p option. The procedure p will be called with two arguments, say p(x, y), and it should return true if and only if x must precede y in the desired ordering, and false otherwise -- that is, p should represent a strict ordering.

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 order statistic is defined using exact arithmetic. To define the order statistic numerically, specify the numeric or numeric = true option.

Examples

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

Compute the second order statistic of a 10-element sample drawn from the normal distribution with parameters 5 and 2.

 > $X≔\mathrm{OrderStatistic}\left(\mathrm{Normal}\left(5,2\right),2,10\right):$
 > $\mathrm{Mean}\left(X\right)$
 ${{\int }}_{{-}{\mathrm{\infty }}}^{{\mathrm{\infty }}}\frac{{45}{}{\mathrm{_t}}{}\sqrt{{2}}{}{{ⅇ}}^{{-}\frac{{\left({\mathrm{_t}}{-}{5}\right)}^{{2}}}{{8}}}{}\left({1}{+}{\mathrm{erf}}{}\left(\frac{\left({\mathrm{_t}}{-}{5}\right){}\sqrt{{2}}}{{4}}\right)\right){}{\left({-}{1}{+}{\mathrm{erf}}{}\left(\frac{\left({\mathrm{_t}}{-}{5}\right){}\sqrt{{2}}}{{4}}\right)\right)}^{{8}}}{{1024}{}\sqrt{{\mathrm{\pi }}}}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{ⅆ}{\mathrm{_t}}$ (1)
 > $\mathrm{Mean}\left(X,\mathrm{numeric}\right)$
 ${2.997285906}$ (2)
 > $\mathrm{plot}\left(\mathrm{PDF}\left(X,t\right),t=0..10\right)$

Now try the second from the right.

 > $Y≔\mathrm{OrderStatistic}\left(\mathrm{Normal}\left(5,2\right),-2,10\right):$
 > $\mathrm{Mean}\left(Y,\mathrm{numeric}\right)$
 ${7.002714090}$ (3)

The following input is invalid.

 > $Z≔\mathrm{OrderStatistic}\left(\mathrm{Normal}\left(5,2\right),11,10\right):$

Generate a random sample of size 100000 drawn from the above distribution and compute the second order statistic.

 > $A≔\mathrm{Sample}\left(\mathrm{Normal}\left(5,2\right),{10}^{5}\right):$
 > $\mathrm{OrderStatistic}\left(A,2\right)$
 ${-3.40601157648346}$ (4)

The Vector returned by Sample has a suitable data type for using the inplace option. The previous call did not use the inplace option, so the elements in A are currently unsorted. After calling OrderStatistic, the second order statistic will be in A[2].

 > $A\left[1..10\right]$
 $\left[\begin{array}{cccccccccc}{5.34071684282082}& {7.01295681750362}& {5.53742535831662}& {2.06803910608245}& {4.92848429232101}& {4.98699327307473}& {4.88563399553352}& {4.63079981075014}& {5.40771080474222}& {4.80225635194575}\end{array}\right]$ (5)
 > $\mathrm{OrderStatistic}\left(A,2,\mathrm{inplace}=\mathrm{true}\right)$
 ${-3.40601157648346}$ (6)
 > $A\left[1..10\right]$
 $\left[\begin{array}{cccccccccc}{-5.02374426654846}& {-3.40601157648346}& {-3.25835036249453}& {-3.23402927603729}& {-2.55397727446371}& {-2.14359446638416}& {-3.07461394713608}& {-1.97207576720959}& {-2.74110950442011}& {-2.38511709696444}\end{array}\right]$ (7)

To get the fourteenth shortest word from a quotation, you can separate it into words and then use OrderStatistic with a custom ordering function.

 > $\mathrm{quotation}≔"The Analytical Engine has no pretensions whatever to originate anything. It can do whatever we know how to order it to perform."$
 ${\mathrm{quotation}}{≔}{"The Analytical Engine has no pretensions whatever to originate anything. It can do whatever we know how to order it to perform."}$ (8)
 > $\mathrm{words}≔\mathrm{remove}\left(\mathrm{type},\mathrm{StringTools}:-\mathrm{Split}\left(\mathrm{quotation},"."\right),""\right)$
 ${\mathrm{words}}{≔}\left[{"The"}{,}{"Analytical"}{,}{"Engine"}{,}{"has"}{,}{"no"}{,}{"pretensions"}{,}{"whatever"}{,}{"to"}{,}{"originate"}{,}{"anything"}{,}{"It"}{,}{"can"}{,}{"do"}{,}{"whatever"}{,}{"we"}{,}{"know"}{,}{"how"}{,}{"to"}{,}{"order"}{,}{"it"}{,}{"to"}{,}{"perform"}\right]$ (9)
 > compare_length := proc(x, y) return length(x) < length(y); end proc;
 ${\mathrm{compare_length}}{:=}{\mathbf{proc}}\left({x}{,}{y}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{return}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{length}}{}\left({x}\right){<}{\mathrm{length}}{}\left({y}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (10)
 > $\mathrm{OrderStatistic}\left(\mathrm{words},14,\mathrm{ordering}=\mathrm{compare_length}\right)$
 ${"order"}$ (11)

References

 Stuart, Alan, and Ord, Keith. Kendall's Advanced Theory of Statistics. 6th ed. London: Edward Arnold, 1998. Vol. 1: Distribution Theory.

Compatibility

 • The Statistics[OrderStatistic] command was updated in Maple 2015.
 • The inplace option was introduced in Maple 2015.