The RANKS function computes the magnitude-based ranks of a sample population X . Elements of identical magnitude "ties" are ranked according to the mean of the ranks that would otherwise be assigned. The result is a vector of ranks equal in length to X .
This routine is written in the IDL language. Its source code can be found in the file
ranks.pro
in the
lib
subdirectory of the IDL distribution.
Define an n -element sample population.
X = [-0.8, 0.1, -2.3, -0.6, 0.2, 1.1, -0.3, 0.6, -0.2, 1.1, $
-0.7, -0.2, 0.6, 0.4, -0.1, 1.1, -0.3, 0.3, -1.3, 1.1]
Allocate a two-column, n -row array to store the results.
array = FLTARR(2, N_ELEMENTS(X))
Sort the sample population and store in the 0th column of ARRAY.
Compute the ranks of the sorted sample population and store in the 1st column of ARRAY.
array[1, *] = RANKS(X[SORT(X)])
Display the sorted sample population and corresponding ranks with a two-decimal format.