**3.5****
****Ranks, Percentiles, Deciles,
and Quartiles** (.NET, C#, CSharp, VB, Visual Basic, F#)

The static Ranks()
method on class **StatsFunctions**
returns the rank of each element in a data set an as array of integers.
For example:

Code Example – C#

int[] ranks = StatsFunctions.Ranks( data );

By default, the ranks are calculated using ascending
order. Alternatively, you can specify a sort order using a value from
the **SortingType**
enumeration. Thus:

Code Example – C#

int[] ranks = StatsFunctions.Ranks( data, SortingType.Descending );

**NOTE—****StatsSettings.Sorting
specifies the default SortingType.**

The Rank() method returns
where a given value *would* rank within
a data set, if it were part of the data set. Again, the sorting order
can be specified using a value from the **SortingType**
enumeration. For instance:

Code Example – C#

double x = 5.342; int rank = StatsFunctions.Rank( data, x, SortingType.Descending );

Percentile() calculates
the value at the *n*th percentile of
the elements in a data set, where . For example,
to find the value at the 95th percentile:

Code Example – C#

double x = StatsFunctions.Percentile( data, 0.95 );

PercentileRank() performs the inverse calculation, returning the percentile a given value would have if it were part of the data set:

Code Example – C#

double x = 23.653; double percentile = StatsFunctions.Percentile( data, x );

The returned percentile value is between 0 and 1.

Similarly, Decile() calculates a given decile, specified as an integer between 0 and 10, of the elements in a data set. Quartile() calculates a given quartile, specified as an integer between 0 and 4. For example, this code finds the third quartile value:

Code Example – C#

double x = StatsFunctions.Quartile( data, 3 );