percentile

Syntax

percentile(X, percent, [interpolation=’linear’])

Arguments

X is a vector or a matrix.

percent is an integer or a floating number between 0 and 100.

interpolation is a string indicating the interpolation method to use if the specified percentile is between two elements in X (assuming the i-th and (i+1)-th element in the sorted X) . It can take the following values:

  • ‘linear’: Return X(i)+(X(t+1)-X(t))*fraction, where fraction = ((percentile100)-(i(size-1)))(1(size-1))

  • ‘lower’: Return X(i)

  • ‘higher’: Return X(i+1)

  • ‘nearest’: Return X(i) or X(i+1) that is closest to the specified percentile

  • ‘midpoint’: Return (X(i)+X(i+1))2

The default value of interpolation is ‘linear’.

Details

If X is a vector, return the given percentile of X. The calculation ignores NULL values.

If X is a matrix, conduct the aforementioned calculation within each column of X. The result is a matrix with the same shape as X.

Examples

$ a=[6, 47, 49, 15, 42, 41, 7, 39, 43, 40, 36];

$ percentile(a,50);
40

$ percentile(a,54);
40.4

$ percentile(a,25,"lower");
15

$ percentile(a,75,"higher");
43

$ percentile(a,5,"midpoint");
6.5

$ percentile(a,5,"nearest");
6
$ m=matrix(1 2 5 3 4, 5 4 1 2 3);
$ m;

#0

#1

1

5

2

4

5

1

3

2

4

3

$ percentile(m, 75);
$ [4,4]