 Statistics - Maple Programming Help

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

Statistics

 Median
 compute the median

 Calling Sequence Median(A, ds_options) Median(X, rv_options)

Parameters

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

Description

 • The Median function computes the median of the specified random variable or data set.
 • 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]).
 • In the first calling sequence, if A has an even number of data points, then the median is the mean of the two middle data points.
 • In the second calling sequence, if X is a discrete random variable, then the median is defined as the first point $t$ such that the CDF at t is greater than or equal to $\frac{1}{2}$.

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 Median command. Missing items are represented by undefined or Float(undefined). So, if ignore=false and A contains missing data, the Median command will return undefined. 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$.

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 median is computed using exact arithmetic. To compute the median numerically, specify the numeric or numeric = true option.

Examples

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

Compute the median of the Weibull distribution with parameters p and q.

 > $\mathrm{Median}\left(\mathrm{Weibull}\left(p,q\right)\right)$
 ${p}{}{{\mathrm{ln}}{}\left({2}\right)}^{\frac{{1}}{{q}}}$ (1)

Use numeric parameters.

 > $\mathrm{Median}\left(\mathrm{Weibull}\left(3,5\right)\right)$
 ${3}{}{{\mathrm{ln}}{}\left({2}\right)}^{{1}}{{5}}}$ (2)
 > $\mathrm{Median}\left(\mathrm{Weibull}\left(3,5\right),\mathrm{numeric}\right)$
 ${2.787958770}$ (3)

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

 > $A≔\mathrm{Sample}\left(\mathrm{Weibull}\left(3,5\right),{10}^{5}\right):$
 > $\mathrm{Median}\left(A\right)$
 ${2.78845957755377}$ (4)

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

 > $X≔\mathrm{Normal}\left(5,2\right)$
 ${X}{≔}{\mathrm{Normal}}{}\left({5}{,}{2}\right)$ (5)
 > $B≔\mathrm{Sample}\left(X,{10}^{6}\right):$
 > $\left[\mathrm{Median}\left(X,\mathrm{numeric}\right),\mathrm{StandardError}\left[{10}^{6}\right]\left(\mathrm{Median},X,\mathrm{numeric}\right)\right]$
 $\left[{5.}{,}{0.00250662827550447}\right]$ (6)
 > $\mathrm{Median}\left(B\right)$
 ${4.99678243370357}$ (7)

Compute the median of a sum of two random variables.

 > $X≔\mathrm{RandomVariable}\left(\mathrm{Normal}\left(5,2\right)\right):$
 > $Y≔\mathrm{RandomVariable}\left(\mathrm{Normal}\left(10,1\right)\right):$
 > $\mathrm{Median}\left(X+Y\right)$
 ${15}$ (8)

Verify this using simulation.

 > $C≔\mathrm{Sample}\left(X+Y,{10}^{5}\right):$
 > $\mathrm{Median}\left(C\right)$
 ${15.0132612858983}$ (9)

Compute the median 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{Median}\left(V,\mathrm{weights}=W\right)$
 ${67.}$ (10)
 > $\mathrm{Median}\left(V,\mathrm{weights}=W,\mathrm{ignore}=\mathrm{true}\right)$
 ${67.}$ (11)

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]$ (12)

We compute the median of each of the columns.

 > $\mathrm{Median}\left(M\right)$
 $\left[\begin{array}{ccc}{3.}& {995.}& {114694.}\end{array}\right]$ (13)

References

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

Compatibility

 • The A parameter was updated in Maple 16.