stats::finiteQuantile

Quantile function of a finite sample space

Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

Syntax

stats::finiteQuantile([x1, x2, …], [p1, p2, …])
stats::finiteQuantile([[x1, p1], [x2, p2], …])
stats::finiteQuantile(s, <c1, c2>)
stats::finiteQuantile(s, <[c1, c2]>)

Description

stats::finiteQuantile([x1, x2, …, xn], [p1, p2, …, pn]) returns a procedure representing the quantile function of the data x1, x2 etc. with the probabilities p1, p2 etc. It is the (discrete) inverse of the cumulative distribution function stats::finiteCDF([x1, x2, …], [p1, p2, …]). For 0 ≤ x ≤ 1, the x-quantile y = stats::finiteQuantile([x1, x2, …], [p1, p2, …])(x) is the smallest of the data elements x1, x2, … satisfying

.

(The data elements are assumed to be ordered: x1 < x2 < x3 etc.)

The procedure f := stats::finiteQuantile([x1, x2, …], [p1, p2, …]) can be called in the form f(x) with an arithmetical expression x.

If x is a real number satisfying 0 ≤ x ≤ 1 and all probability values p1, p2, … are numerical, then f(x) returns one of the data elements x1, x2, ….

Otherwise, if x is a symbolic expression that cannot be converted to a real floating-point number or if the probabilities p1, p2, … contain elements that cannot be converted to real floating-point numbers, then f(x) returns the symbolic call stats::finiteQuantile([x1, x2, …], [p1, p2, …])(x) with the data x1, x2, … in ascending order.

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

If all probability values p1, p2, … are numerical, they must add up to 1. Otherwise, an error is raised.

Duplicate data elements are automatically combined to a single data element, adding up the corresponding probability values. Cf. Example 5.

y = stats::finiteQuantile([x1, x2, …], [p1, p2, …])(x) satisfies

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

The data elements x1, x2, … are assumed to be in ascending order: x1 < x2 < …. If all data elements are numerical, they are re-ordered automatically, if they are not ascending. If the data contain symbolic elements that cannot be converted to floating-point numbers, the ordering is assumed implicitly.

stats::finiteQuantile generalizes stats::empiricalQuantile, which assumes equiprobable data. For numerical data x1, x2, …, the call stats::finiteQuantile([x_1, dots, x_n], [1/n, dots, 1/n]) corresponds to stats::empiricalQuantile([x1, …, xn]).

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 some numerical data:

f := stats::finiteQuantile([1, x, y, PI],
                           [1/4, 3/8, 1/4, 1/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::finiteQuantile([[1, 1/4], [x, 3/8],
                            [y, 1/4], [PI, 1/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 symbolic arguments. In the symbolic return value, the input data appear as a sorted list:

f:= stats::finiteQuantile([3, 4, PI], [0.2, 0.5, 0.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, 2/5],
   ["1997", 1353, 0.1],
   ["1998", 1142, 0.2],
   ["1999", 1201, 0.2],
   ["2001", 1201, 0.1]])
"1996"  1242  2/5
"1997"  1353  0.1
"1998"  1142  0.2
"1999"  1201  0.2
"2001"  1201  0.1

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

f := stats::finiteQuantile(s, 2, 3):
f(0.1), f(1/4), f(0.7), f(99/100)

delete s, f:

Example 4

If numerical probability values are given, they must add up to 1:

f := stats::finiteQuantile([Head, TAIL], [0.45, 0.54]):
Error: The probabilities do not add up to one. [stats::finiteQuantile]

Symbolic probability values are not checked for consistency:

f := stats::finiteQuantile([Head, TAIL], [0.45, p]):
f(x)

However, when the probabilities are set to numerical values, they are checked:

p:= 0.7: f(x)
Error: The probabilities do not add up to one. [f]
delete f, p:

Example 5

Duplicate data elements are automatically combined to a single data element, adding up the corresponding probability values:

f:= stats::finiteQuantile([x1, x2, x1, x2], [p1, p2, 0.3, 0.4]):
f(0.5)

p1 := 0.1: p2 := 0.2: f(0.5)

delete f, p1, p2:

Parameters

x1, x2, …

The statistical data: arbitrary MuPAD® objects

p1, p2, …

Probability values: arithmetical expressions

s

A sample of domain type stats::sample

c1, c2

Column indices of the sample s: positive integers. Column c1 provides the data x1, x2 etc. Column c2 provides the data p1, p2 etc. There is no need to specify column numbers if the sample has only two columns.

Return Values

procedure.

Was this topic helpful?