RangeFractile - script and chart function

RangeFractile() returns the value that corresponds to the n-th fractile (quantile) of a range of numbers.

Note: RangeFractile() uses linear interpolation between closest ranks when calculating the fractile.

Syntax:  

RangeFractile(fractile, first_expr[, Expression])

Return data type: numeric

Arguments:  

The arguments of this function may contain inter-record functions which in themselves return a list of values.

Argument Description
fractile A number between 0 and 1 corresponding to the fractile (quantile expressed as a fraction) to be calculated.
first_expr The expression or field containing the data to be measured.
Expression Optional expressions or fields containing the range of data to be measured.

Add the example script to your app and run it. Then add, at least, the fields listed in the results column to a sheet in your app to see the result.

RangeTab:

LOAD recno() as RangeID, RangeFractile(0.5,Field1,Field2,Field3) as MyRangeFrac INLINE [

Field1, Field2, Field3

10,5,6

2,3,7

8,2,8

18,11,9

5,5,9

9,4,2

];

The resulting table shows the returned values of MyRangeFrac for each of the records in the table.
RangeID MyRangeFrac
1 6
2 3
3 8
4 11
5 5
6 4

Examples and results:  

Examples Results
RangeFractile (0.24,1,2,4,6) Returns 1.72
RangeFractile(0.5,1,2,3,4,6)

Returns 3

RangeFractile (0.5,1,2,5,6)

Returns 3.5

Example with expression:

RangeFractile (0.5, Above(Sum(MyField),0,3))

In this example, the inter-record function Above() contains the optional offset and count arguments. This produces a range of results that can be used as input to the any of the range functions. In this case, Above(Sum(MyField),0,3) returns the values of MyField for the current row and the two rows above. These values provide the input to the RangeFractile() function. So, for the bottom row in the table below, this is the equivalent of RangeFractile(0.5, 3,4,6), that is, calculating the 0.5 fractile for the series 3, 4, and 6. The first two rows in the table below, the number of values in the range is reduced accordingly, where there no rows above the current row. Similar results are produced for other inter-record functions.

MyField RangeFractile(0.5, Above(Sum(MyField),0,3))
1 1
2 1.5
3 2
4 3
5 4
6 5

Data used in examples:

RangeTab:

LOAD * INLINE [

MyField

1

2

3

4

5

6

] ;

Did this information help you?

Thanks for letting us know. Is there anything you'd like to tell us about this topic?

Can you tell us why it did not help you and how we can improve it?