stats::empiricalQuantile

Quantile function of the empirical distribution

Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

Syntax

stats::empiricalQuantile(x1, x2, …)
stats::empiricalQuantile([x1, x2, …])
stats::empiricalQuantile(s, c)

Description

stats::empiricalQuantile(x1, x2, …) returns a procedure representing the quantile function of the data x1, x2 etc. It is the (discrete) inverse of the empirical cumulative distribution function stats::empiricalCDF(x1, x2, …). For 0 ≤ x ≤ 1, the x-quantile y = stats::empiricalQuantile(x1, x2, …)(x) is the smallest of the data elements x1, x2, … satisfying

.

All data x1, x2, … must be convertible to real floating-point numbers. The data do not have to be sorted on input.

The procedure f := stats::empiricalQuantile(x1, x2, …) can be called in the form f(x) or f(x, Averaged) with an arithmetical expression x.

If x is a real number satisfying 0 ≤ x ≤ 1, then f(x) returns one of the data elements; f(x, Averaged) uses interpolation of adjacent data elements:

The x-quantile of n sorted values x1 ≤ … ≤ xn is computed as follows.

  • f(x) returns xk with k = ceil(n*x).

  • f(x, Averaged) returns xk with k = ceil(n*x) if nx is not an integer. Otherwise, it returns .

If x is a symbolic expression that cannot be converted to a real floating-point number, f( x , <Averaged>) returns the symbolic call stats::empiricalQuantile([x1, x2, …])(x, <Averaged>) with the data x1, x2, … in ascending order.

Numerical values of x are only accepted if 0 ≤ x ≤ 1.

y = stats::empiricalQuantile(x1, x2, …)(x) satisfies

for all data elements z in the sample satisfying z < y.

For a sample of size n, the call f := stats::empiricalQuantile(x1, x2, …) needs a run time of O(nln(n)) due to internal sorting of the data. The costs of a call to f are essentially dependent of n. If several evaluations of the quantile function are needed, a calling sequence such as

f := stats::empiricalQuantile(x1, x2, …); f(a1); f(a2); dots

is more efficient than

stats::empiricalQuantile(x1, x2, …)(a1);

stats::empiricalQuantile(x1, x2, …)(a2);

dots.

The -quantile is called "median". The function stats::median implements this special quantile.

stats::empiricalQuantile is generalized by stats::finiteQuantile, which allows to specify different probabilities for the elements of the sample. The call stats::empiricalQuantile([x1, …, xn]) corresponds to stats::finiteQuantile([x_1, dots, x_n], [1/n, dots, 1/n]).

Further, stats::finiteQuantile does not only allow numerical values x1, x2, …, but arbitrary MuPAD® objects.

Environment Interactions

The function is sensitive to the environment variable DIGITS which determines the numerical working precision. Note, however, that this function is implemented with option remember. After the first call it does not react to changes of DIGITS unless the input parameters are changed.

Examples

Example 1

We compute various quantiles of the data -1, 0, 0, 2.3, PI, PI, 8:

f := stats::empiricalQuantile(-1, 0, 0, 2.3, PI, PI, 8):
f(0), f(0.1), f(3/10), f(0.5), f(1/sqrt(2)), f(99/100), f(1)

Alternatively, the data may be passed as a list:

f := stats::empiricalQuantile([-1, 0, 2.3, PI, 8]):
f(0), f(0.1), f(3/10), f(0.5), f(1/sqrt(2)), f(99/100), f(1)

delete f:

Example 2

We use a symbolic argument. In the symbolic return value, the input data appear as a sorted list:

f := stats::empiricalQuantile(3, 25, PI, 4/3): f(x)

Numerical values for x are only accepted if 0 ≤ x ≤ 1:

f(0.5)

f(2)
Error: An argument x with 0 <= x <= 1 is expected. [f]
delete f:

Example 3

We create a sample of type stats::sample consisting of one string column and two non-string columns:

s := stats::sample(
  [["1996", 1242, PI - 1/2], ["1997", 1353, PI + 0.3],
   ["1998", 1142, PI + 0.5], ["1999", 1201, PI - 1/3],
   ["2001", 1201, PI + 0.5]])
"1996"  1242  PI - 1/2
"1997"  1353  PI + 0.3
"1998"  1142  PI + 0.5
"1999"  1201  PI - 1/3
"2001"  1201  PI + 0.5

We compute quantile values of the data in the second and third column, respectively:

f2 := stats::empiricalQuantile(s, 2):
f2(0.1), f2(1/4), f2(0.7), f2(99/100)

f3 := stats::empiricalQuantile(s, 3):
f3(0.1), f3(1/4), f3(0.7), f3(99/100)

delete s, f2, f3:

Parameters

x1, x2, …

The statistical data: real numerical values

s

A sample of domain type stats::sample

c

A column index of the sample s: a positive integer. This column provides the data x1, x2 etc. There is no need to specify a column number c if the sample has only one non-string column.

Return Values

procedure.

Was this topic helpful?